blog.fgsfd.se

Debian / OS X Perl locale issue

If you run see this when running Perl it’s because OS X Terminal.app sets LC_CTYPE to “UTF-8” when it should be a locale string like the others. Set it to en_US.UTF-8 to fix it.

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = "en_US:en",
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

Mac OS X Password Assistant API

image

Keychain Access uses a private API in SecurityFoundation.framework to power the above dialog. I like the passwords it generates, but I wanted to use it from the terminal instead of launching Keychain Access every time I need a password.

Last summer I used Hopper Disassembler and gdb to reverse engineer a few of the functions, which resulted in my tool sf-pwgen. Last month I dusted the code off a bit, and while doing so I added more function declarations.

image

You can find the header in my SecurityFoundation repository at Bitbucket.

(Updated 2014-03-31 to fix broken URLs)

Add current track to monthly playlist

This script will add the currently playing track to a monthly playlist (format: YYYY-mm). It creates it if it doesn’t exist. I’ve bound the script to F6 using Quicksilver.

Remove duplicate tracks in an iTunes playlist

How to determine the DHCPv6 DUID in Lion

I couldn’t find this on Google, even after many hours of searching. I managed to figure it out eventually. Here’s how (output slightly modified):

Adding the currently playing track to a playlist using AppleScript

I’m not very good at using AppleScript, but here’s a simple script that you or someone else might find useful.

Restoring the Recovery HD in Mac OS X Lion perfectly

Background:

I have an iMac. It originally came with Snow Leopard installed. I upgraded to Lion but later realized I wanted a clean install, so I installed Lion to an external drive and then restore it onto the iMac HDD. I used Carbon Copy Cloner (CCC) to do that, but it turned out that CCC won’t copy the hidden Recovery HD partition…

The procedure:

  1. Install Lion in VMware Fusion 4. This is quite easy, you just choose the Lion installer app instead of a disk image when setting up a new VM.

  2. Copy the disk0s3 (recovery partition) to a file in the VM, then copy it to the host. This is accomplished using dd.

  3. Restore the recovery clone to the host disk0s3 (note: the GPT layout must match). The following GPT is for my 1 TB drive.

  4. Set the “Media Name” of the recovery partition to “Recovery HD” to make it fully compatible with OS X. This can either be done using the gpt tool or parted from a Linux live CD. I used the latter.

To change it using gpt (note, you have to do it from an OS X installer/recovery environment that runs off a different drive than the drive you’re modifying):

Using gpt: gpt label -i 3 -l "Recovery HD" disk0.

Using parted: name 2 'Recovery HD' (not sure if it’s 2 or 3, verify using print before running it)

If you’re interested in doing this yourself, I recommend you read these two blog posts that helped me along the way:

His instructions don’t take the media name into account, which makes certain tools like the Apple Recovery Disk Assistant fail. That’s what I solved today, hope it helps someone out there! :)