Entry tags:

Datestamping in MacOS

Okay, I finally figured out how to make a nigh-universal (~all app) keystroke command which will plop the current date stamp, in the format of my chosing, wherever the cursor is.

This was a ridiculous amount of effort.

But as of right now, I have a service in Users/$me/Library/Services/PutDate that I have mapped to the Keyboard Shortcut (in System Preferences > Keyboard > Shortcuts) shift-option-Apple-d. Works fine.

Internally, it's pretty grody. Apparently if you want a date and a time, the only way to concatenate them into the same string is by calling out to a... shell script? Or so saith this discussion on discussions.apple.com.

This other discussion on discussions.apple.com shows exactly what I want to do, but doesn't actually work in practice because of an apparently unresolveable permissions error. Apparently when it says "any such application" what it means is any application you want this to work in has to be manually granted the permission to run the script in the sys prefs, which ha ha ha, omg no.

At least doing it the other way, I get to format the date/time to my liking!

Entry tags:

Groenendijk's Link Text and Location Copier

Well, damn.

I installed William Groenendijk's "Link Text and Location Copier" plug-in to my install of Firefox, and liked it plenty. Wondering if it could be expanded a little, I looked it back up on the FF extensions directory to find a way of reaching out to the developer, and on clicking the developer name discovered:

The creator of this add-on has sadly passed away. No further updates will be made. Please feel free to keep using this add-on as is. Thank you.
I looked at this homepage, evilnickname.org, and I guess he died not long after Feb 2019, which is when he stopped updating his blog. Happily, that lead me to his github repository: evilnickname / link-text-location-copier . Bless you, evilnickname, for githubbing your code! I guess if I want those features, I can try to make them myself. I don't know the first thing about coding FF extentions, but I guess that could go on the great to-do list.

Entry tags:

pinboard bookmark import difficulties

Hrm. I am trying to manually manufacture a bookmark import file for use with pinboard.in, based on the NETSCAPE-Bookmark-file-1 format, using a previouslly successfully imported file as a template, and it keeps failing to parse. V. frustrating.

The test file has a single bookmark in it; I have an approximately 80 bookmark file about ready to go in, if I can just figure out what I'm doing wrong.

I already have a support request in for something else; I may wait on a reply before submitting this.

Entry tags:

Feeling clever: tcsh completions for my custom inc

I finally got a round tuit, which I poached from actually important things, and finally figured out how to set up autocompletion in tcsh for my custom inc, inca, with the spools list.

Dear self, the config file is ".tcshrc.nmh" which we apparently call from somewhere useful.

The magic lines are:

set nmh_mail_spools = awk '{print $1}' $HOME/.vnmhx.spools | tr "\n" " " complete inca 'C/*/$nmh_mail_spools/'

Note this is unnecessarily baroque, and we could have just used the spools directory instead.

Credit to:

man complete: https://www.ibm.com/support/knowledgecenter/SSLTBW_2.4.0/com.ibm.zos.v2r4.bpxa500/tcshcomplete.htm

Examples: https://hea-www.harvard.edu/~fine/Tech/tcsh.html

man sed: https://www.gnu.org/software/sed/manual/sed.html#sed-script-overview

how not to use sed at all: https://www.unix.com/shell-programming-and-scripting/162226-convert-rows-space-delimited-line.html

Entry tags:

Keyboard enabled fast user switching for Mac OS (10.15)

Okay, so I decided my life would be better if I factored it into multiple users on my regular box, which is a MacBook Pro running Catalina (10.15).

I turned on Fast User Switching, which I guess puts the user menu in the upper right? I find using menus to switch users really annoying. I want to switch users without taking my hands off the keyboard.

So I go looking for the keystroke shortcut for this, and rapidly discover there is none.

After a hell of a lot more searching, I discover this:

https://hints.macworld.com/article.php?story=20110813074611411

which is terrible because it stores the password in plaintext, but that's okay, I am willing to type out the password, but also terrible because AppleScript.

But this:

https://superuser.com/questions/44433/create-a-keyboard-shortcut-for-fast-user-switching-in-mac-os-x

Which points out you can just call the relevant thing from a shell script, only that flag doesn't work, possibly because that's an answer for a question in Snow Leopard (10.6.8).

But this:
https://blog.taylormcgann.com/tag/cgsession/

has information about flags for that command, and also explains how to use it with Automator. What the hell is Automator? What it sounds like.

So what I realized I wanted is a keystroke command that would not take me to the screen from which I could select another user, because mouse, but would take me to the screen with a specific user selected and prompting me for a password. This means I need to do this for each user I want to switch to, times how many users I have minus 1. I have two user accounts, so I had to do this twice.

To do this, you need the magic command, and you need to call it on your user id's number. To get this number, use the command embedded in that above Apple Script: /usr/bin/id -u + whatever username you want to switch to.

When you fire up Automator and prod it to make you a new Automator thing, the correct option for this purpose is a new "Quick Action", because Quick Actions are/can be (?) Services. And Services can be assigned to Finder keystroke shortcuts.

So create a new "Quick Action", and in the third pane, the first option is "Workflow received current" and a pull down menu. Choose "no input" all the way at the bottom. Then in the left pane, select, under Library, "Utilities"; in the middle pane, find "Run Shell Script" and drag it into the right pane. Pick a shell in the shell menu (when in doubt, /bin/sh) and in the textbox write:
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID `/usr/bin/id -u YOURTARGETUSERNAMEHERE`
Only use your username instead of YOURTARGETUSERNAMEHERE.

I didn't do this. Instead, I ran /usr/bin/id -u YOURTARGETUSERNAMEHERE at the Terminal and then hard coded the returned number into the script, which looks like
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 501
Hard coding the user number makes it slightly faster.
Save this. Give it a name like "Switch to YOURTARGETUSERNAMEHERE". Note: I have no idea where in the filesystem it winds up. The important thing is that if you do this all correctly, you can now fire up System Preferences, go to Keyboard, select the Shortcuts tab, then in the left pane select Services, and then scroll the right pane all the way to the bottom, and there, under General, you should see "Switch to YOURTARGETUSERNAMEHERE". Assign it a keystroke combination that you can remember and find convenient and doesn't clash too bad with any used elsewhere (I used shift-command-s (for "switch") and promptly discovered it conflicts with Terminal's Save Selected Text) and – voila!

Now, go log into the other account, and do the same thing, only with the previous account as the target, there. You can use the same keystroke for both, because they won't clash.

You'll need more keystroke options, though, if you have three or more users to switch among. If you have three accounts, you'll want account A to have a keystroke for account B and another keystroke for account C, account B to have keystrokes for accounts A and C, and account C to have keystrokes for accounts A and B. Good luck.

More on running Mac OS 10.6.8 in a VirtualBox VM on Mac OS 10.15.1

We have hit a snag.

I would like to put a document into my instance.

The internet says this is easy, there's a built-in file manager (to VirtualBox) to do this. But it does not work for me.

I discover that to make it go, I have to install "Guest Additions". Okay. There's a menu item in the VM instance manager, VirtualBox VM, under "Devices", "Insert Guest Additions CD Image". I click that, and *poof* a disk image appears on the virtual machine's desktop ("VBox_GAs_6.0.14"). It does not autorun, so I open it. I try running the autorun.sh in Terminal. This throws a "can't find Linux/Solaris device" error. Finally, I double-click on "VBoxDarwinAdditions.pkg". This lauches the installer, which promptly throws an error:
Incompatable OS version detected!

VirtualBox Guest Additions require Mac OS X 10.7 or later running in 64-bit mode.
Well then.

Hrm.

UPDATE: I asked on the support board, and I was pointed at instructions for understanding the networking, and told to just share files like between physical machines. Sounds good to me, but I am going to sleep at a reasonable time tonight; it will have to wait till tomorrow.

Installing Mac OS 10.6.8 from media in Oracle's VirtualBox on Mac OS 10.15.1

Okay, so.

Ingredients:

MacBook Pro w/ 1T space and 64G memory, running Catalina (Mac OS 10.15.1)
Mac SuperDrive
Mac USB-to-Thunderbolt adaptor
Oracle VirtualBox (free, downloadable)
Snow Leopard (Mac OS 10.6.8) install DVD

Steps:

Download and install VirtualBox.
It wants to violate your privacy/security like whoa - I guess you have to let it??
Click NEW.
Most of the defaults are sensible.
One of the options is "New 10.6.8 Install", which FAR OUT.
But! It wants to know: 10.6.8 32 bit or 10.6.8 64 bit?
Since I'm testing for ultimately moving my old 10.6.8 machine's contents into a virtual machine, I'd better do the same thing. But... what is it running?
Googling "how to tell mac 32 vs 64 10.6.8" got me this web page which said to fire up terminal and run the command uname -a and...:
If you’re using a 32 bit Kernel in Mac OS X:
iMac:~ user$ uname -a
Darwin iMac.local 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 
22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386

See the i386 on the end there? That indicates it’s the 32 bit kernel

If you’re using a 64 bit Kernel in Mac OS X:
iMac:~ user$ uname -a
Darwin iMac.local 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 
22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_X86_64 x86_64

The x86_64 at the end will let you know you are using the 64 bit kernel.

You can alternate between the two by holding down “6” and “4” during system boot to load the 64 bit kernel, or holding down ‘3’ and ‘2’ during boot to use the 32 bit kernel. Your machine should default into the kernel that is best supported
So I have 32 bit 10.6.8. So that's what I select.
VirtualBox asks me if I'd like to install the OS now, and if so, where is it?
I belatedly unpackage my SuperDrive, and discover it won't mount on my USB hub - it complains of insufficient power - so it has to hog the USB-to-Thunderbolt adaptor all to itself, and I have to use the built-in keyboard and scratch-n-sniff for all the rest of this, ugh.
By the time I get the drive attached and the installer DVD in it, and this assemblage shared with the "guest" virtual machine, Virtual Box has kind of given up on me? And I wind up with a virtual machine with no OS. Lovely.

Also, I should note that this thing came up in a glorified postage stamp of a window. I forget how I ultimately got it to be a reasonable size I could, you know, read, but that was another 10 minutes of wandering around lost in the application.

With so farting around, I eventually restart the virtual machine, with the instruction to boot from media; the DVD is of course bootable.

This is not fast but by god it happens, and eventually I am greeted by the sunny face of the Snow Leopard installer asking if I wanted to install onto this machine it thinks it is booting. Yes, yes I absolutely want to do exactly that omg this is working.

Everything is so promising, then it says, "Okay, sure. Select the drive onto which you want to install the OS" and there are NO drives listed. I'm like: bwuh? I just made you a nice virtual disk?? Where did it go?? Virtual Box itself is sure it's there and attached to this virtual machine. Mac installer can't see it.

But! The installer also gives you access to a variety of tools when you're booted from it, including Disk Utility.

Disk Utility tells me that the virtual drive is totally there, it's just unformatted. I'm like "...really? Is that all?" So I go to Erase, and Erase the virtual disk, which reformats it, which because it is 20G and is empty takes approximately 1.5 seconds, and then, boom, there's the volume in the selection pane. I quit Disk Utility and, lo! the installer can see my new virtual drive. "Install here?" YES, YES MY MINIONS! BWAHAHAH!

And it said it was gonna take a half hour, so I am typing this up now on my old 10.6.8 machine while it does it's thing. /giddy

Oh, hey! It got through that faster than it said. It claims it has finished installing, and now it has come up into the normal 10.6.8 default Finder interface. Okay, let's see if it it actually worked: power down the instance, quite Virtual Box VM (which actually crashes, instead), eject the DVD, unmount the SuprDrive (and re-attach the USB hub so I can use my real keyboard), and restart it.

Some difficulty getting it to restart, apparently because of the crash, but eventually: success! It boots into a fresh install of 10.6.8 off the virtual disk, and makes me do all the irritating things to register the software or whatever and configure a first account (note to self: "admin" with the "aa" password.)

Tada! I have a virtual machine running 10.6.8. Feels a bit pokey/laggy; I wonder if that's because I only gave the instance 2G memory, or if that's just virtualization for you.
Entry tags:

You can return a js function's source!

OMGOMGOMG, I just discovered javascript's Function.prototype.toString() method.

Example:

function foo (
  alert ( "Hello, World!" );
}

alert ( foo.toString ); 
... causes an alert pop-up to display with a text of function foo \n(\t alert ( "Hello, World!" );\n} (only with all those tabs and returns rendered correctly).

I think I am hyperventilating.

I am going to get in so much trouble with this.

Once I stop cackling maniacally and dancing around the house in ecstacy.
Entry tags:

What is this "backing_file" on my NAS?

Huh. I was creating a new shared folder on my NAS through its web interface, clicked on the wrong thing, and discovered its drive is pretty close to full.

Well, I figure I've been putting a lot of backups on it. Maybe the pruner for that or the log rotater isn't doing what it should? But no, those are fine.

Then, poking around, I accidentally discovered that in the shared folders directory (/mnt/disk/volume1), there's a file called "backing_file", which is 400G. It's binary, and hasn't been updated since Apr 17 2013.

WTH?

I'm trying to decide if I can delete it or not. It's not impossible I created it by mistake, back when I was setting up my backup system, but I don't know how. Google's only apparent association with that string and Debian is for a utility, qemu-img, which I'd never heard of. I've not messed around with disk images in years and years, and never on that device.
Entry tags:

LJ LFs

WTELF. I am trying to – yes, yes, I know – do regexes on dumps of the LJ Inbox, and I just discovered that something Very Weird is going on with the linefeeds.

Mostly everything is fine. Except the part that isn't: The actual message contents seem to have line breaks between, er, lines (at least everything that renders that thinks they're line ends – View Source in Firefox, more at the command line, BBEdit) except that perl isn't seeing them as line breaks. Perl thinks (okay, while (my $line = <INBOXFILE>) returns) they're all one big happy line with some sort of line break in them. Running against that string regex that matches just the HTML at the end ($line =~ /<div class=\'actions\'>/) doesn't just return the last line of the message, it returns almost the whole damned message.

To confirm this, I wrote a perl script to simply number the lines of the raw HTML. It returned something like the following (heavily redacted because privacy and not escaping all the damned angle brackets):
[...]

522:                 <td class="item">

523:                     <div class="InboxItem_Controls"><a href='http://www.livejournal.com/inbox/?page=1&bookmark_off=3320'><img src='../../l-stat.livejournal.net/img/flag_off.gif' width='16' height='18' class='InboxItem_Bookmark' border='0' /></a> 

524:                 <a href="http://www.livejournal.com/inbox/?page=1&expand=3320"><img src="../../l-stat.livejournal.net/img/expand.gif%3Fv=8234" class="InboxItem_Expand" border="0" onclick="return false" /></a>

525:                 </div>

526:                     <span class="InboxItem_Title InboxItem_Unread" id="all_Title_3320"><div class='pkg'><div style='width: 60px; float: left;'><img src="../../l-userpic.livejournal.com/19583817/961489" width="50" align="top" /></div><div>Re: (no subject)<br />from HTMLHTMLHTML...

527:                     

528:                 <div class="InboxItem_Content" style="display: block;">Yes, exactly that one!  Thank you so much.  blah blah blah it's an awesome post, and I'm so glad you helped me find it again.
<br />
<br />randomusername
<br />
<br />--- I wrote:
<br />> This one? URLgoeshere
<br />> <br />> --- randomuername wrote:
<br />> > Sorry for bothering you, but was it you that wrote the awesome post about the blah blah blah?  I can't find it despite googling a lot, so I thought I'd ask... <div class='actions'> <a href='http://www.livejournal.com/inbox/compose.bml?mode=reply&msgid=80595787'>Reply</a> | <a href='http://www.livejournal.com/friends/add.bml?user=randomusername'>Add as friend</a> | <a href='http://www.livejournal.com/inbox/markspam.bml?msgid=80595787' class='mark-spam'>Mark as Spam</a></div></div>

529:                 

530:                     </td>

[...]

What I think should happen is that only the "line" that starts <br />> > Sorry for bothering you etc should be returned by matching on the attribute of that tag at the end. What I'm getting is everything here marked 528 and in bold.

As always, the questions are:

1) Why is it doing this to me? (Is there something actually different about those linefeeds? My text editor seems to think they're identical.)
2) What is doing this to me? (Is this perl being weird?)
3) How do I make it stop? (Can I convince perl not to do what it's doing and do something that make more sense?)

Advice welcome. Meanwhile, I'm necessarily just going to live with it. Don't have time to wrestle this alligator on my way across the swamp.
Entry tags:

Greasemonkey Script: LJ ToS-Boss

Does two things:

1) Removes the ToS modal overlay.

2) Unfolds all Inbox messages.

Enjoy...
// ==UserScript==
// @name        Codeswitcher's LJ ToS-Boss
// @namespace   http://livejournal.com
// @description FU SUP
// @include     http://*.livejournal.com/*
// @include     http://*.livejournal.com
// @version     2
// @grant       none
// ==/UserScript==

window.onload = function () {
  document.body.setAttribute("class","s-horizon logged-in");   
  var hackthisStylesheet = document.styleSheets[document.styleSheets.length - 1 ];
  hackthisStylesheet.insertRule(".InboxItem_Content { display: block !important; }", 0); 
 }
Entry tags:

Fun with LJ's sharing buttons

So, I just discovered you can replace (I mean manually) the href="javascript:void(0);" in the a tags with actual GET strings to, e.g. Twitter's sharing doohicky, HOWEVER,

while

https://twitter.com/intent/tweet?url=http%3A%2F%2Fcodeswitcher.dreamwidth.com%2F131.html%3Futm_source%3Dtwsharing%26utm_medium%3Dsocial&text=Post%20Idea&;

Is fine

https://twitter.com/intent/tweet?url=http%3A%2F%2Fcodeswitcher.dreamwidth.com%2F131.html%3Futm_source%3Dtwsharing%26utm_medium%3Dsocial&text=Post%20Idea&hashtags=LJ,programming

instead triggers LJ's javascript pop-up sharing thingy, for no obvious reason, and does not actually follow that link on clicking.

https://twitter.com/intent/tweet?url=http%3A%2F%2Fcodeswitcher.dreamwidth.com%2F131.html%3Futm_source%3Dtwsharing%26utm_medium%3Dsocial&text=Post%20Idea&hashtags=

Does the javascript thing, too.

Huh. The trigger seems to be the word "hashtags"? How bizarre.

Fortunately, that's an undesirable feature anyway, so good riddance.
Entry tags:

LJ2DW Filter Importation Scripts

I wrote some scripts to automate the granting of access filter privileges in Dreamwidth, for recent importees from Livejournal.

They're in perl, and use wget, and are for the command line, and require that you figure out how to come up with a cookie file.

Instructions in the README.md

They are here on Github.

There are many improvements that could be made, but I think I should move on to trying to address some of the other outstanding importation problems.

I so clearly have no idea how to use github. Suggestions of every sort are welcome, including just which license I should release this under.
Entry tags:

Notes for WP handling images

Maybe WP.com could be used as a repository for images for LJ refugees. They give 3G of storage for free account. It doesn't, of course, honor LJ's permissions schemes. A question arises how exposed individual images are by URL. Can the existence of images be derived from other evidence?

The best solution may be to have different accounts (!) for different permissions levels.

WP.com has an API:

https://developer.wordpress.com/docs/api/

It allows for upload of images (media!) and editing metadata.

Uses OAuth2, has to be a registered application.

(This ask on Stackoverflow is what twigged me to the existence of the WP.com (as opposed to WP.org) API.)

How to use wget to fetch locked things on LJ and DW

h/t to [personal profile] antennapedia on LJ, "Making a local archive with wget"

You can use wget (if you have wget) to fetch pages off LJ and DW that you can only access logged in by this handy method:

1) Install the "Export Cookies" add-in to FireFox (presumably there are ways to pull this off with other browsers, but this is what I did.)

2) Log in to LJ or DW as appropriate.

3) Run "Export Cookies" and put the resultant cookie file somewhere you can find it.

4) Call wget like so:
wget --cookies=on --keep-session-cookies --save-cookies /path/to/newcookie.txt --load-cookies /path/to/ff_exported_cookes.txt --header "X-LJ-Auth: cookie" http://www.livejournal.com
substituting whatever url you want for "http://www.livejournal.com".

On DW, the "X-LJ-Auth" header field name still works, as does "X-DW-Auth".

It's like they know me

github's repository name randomizer just proposed my new repository be named "didactic-winner".

Maybe not.
Entry tags:

A Minimalist Backup System for a Mailman List on Someone Else's Server

Did you ever wonder whatever happened to the Daughter of Bilitis?

It was destroyed when a disgruntled member/volunteer stole the sole copy of the list of members. Bam! End of organization.

Mailman is a popular list server with a web-based self-service interface for users. It has many fine features, none of which are a way to back up your actual membership list (to say nothing of your archives and config files) from the web interface.

Since the vast majority of Mailman list owners/moderators are apparently customers running their lists on Mailman servers operated by web hosting companies for their customers, the vast majority of Mailman list owners/moderators do not have command-line access to the Mailman install running their list and they have no way to back up their data, save asking their hosting company to do that for them (manually!)...

Or this.

The one thing you can back up is the list of email addresses of a list and the associated personal names, and the one way to do it is through the email interface.

Manually, this is simple enough. Email [$listname]-request@domain.tld with "who $adminpassword" in the body of the message. The list will be emailed back to whatever address you sent it from. Lovely.

What follows is a description of my automated system for firing off such an email every night, using nmh, procmail, and cron.

cut for length )
Entry tags:

How to enable incoming plus addressing in Cpanel

Enabling plus addressing in Cpanel should be easy, what with all the layers of email filtering it presents the domain owner. The way to enable plus addressing is to filter incoming email on the basis of to whom its addressed. If you're fred@domain.tld, and want plus addressing to work, all forms of fred+arbitrarystring@domain.tld need to get routed to fred@domain.tld. That's a job for email filtering.

Alas, Cpanel presents the user with no way to filter incoming email on the basis of who it's really addressed for, i.e. the recipient specified in the envelope of the message. This is the address you really want for filtering, because without it, BCC and email list messages aren't delivered when you try to filter on the recipient. To add insult to injury, a "Envelope-to" field is added to messages at delivery -- after all filtering is done.

Cpanel is exim under the hood, and, frankly, the best thing about cpanel+exim is that it allows you to call out to some other real filtering program, if available.

And procmail, which is such a real filtering program, is on many linuxes by default. And it, in turn, can call perl so you can really get something accomplished.

So the answer to "How can I filter by the Envelope-To in cpanel+exim?" is "You can't. But you can call something that can."

Instructions. Cut for epic length. )