Open in Textmate Service

Listening to the new podcast by the ever-present Dan Benjamin and the effervescent Merlin Mann today reminded me of the one Mac OS X service I wrote, that I use almost daily.

It allows me to right-click on the filename line in a python traceback, and have the file opened at that line in Textmate. If the file is part of an already open project, it will open in the project window (unless it is open in another window, in which case that may pop to front).

Fairly simple stuff, and should be easy to extend for other traceback/output types.

Am I connected remotely?

I now share my dotfiles between the various OS X machines I use daily, using Dropbox and symlinks.

However, I have many aliases and functions that need to act differently if I only have a console session at the machine in question, or a full GUI session.

With bash, this is easy to test:

1 export EDITOR='nano'
2 if [[ -z "$SSH_CONNECTION" && $OSTYPE =~ ^darwin ]]; then
3 export EDITOR='mate --wait'
4 export TEXEDIT='mate -w -l %d "%s"'
5 export LESSEDIT='mate -l %lm %f'
6 fi

Now, if I am remotely connected to a machine, then I will get nano as my editor, but if I am sitting directly in front of it, then it will open Textmate.

Copy password button in

I don’t know if this is new or not, but I haven’t noticed it before. My normal workflow for and finding a forgotten password (ie, my Twitter one to put into a new app) is to open the password entry, and copy the value.

Today, I noticed a Copy button at the bottom of the window:

Keychain Access

This still requires you to enter your keychain password to authorise the copy, but saves a step or two.

View man pages in Preview

It’s not a new concept, but here is my take on it:

 1 function man {
 2     # We can get the actual path to the man command here, so we can override
 3     # it with our function name.
 4     MAN=`which man`
 5     # Change these two if you are not on OS X.
 6     CACHE_DIR="${HOME}/Library/Caches/manpages"
 7     OPEN="open"
 9     # If we don't have any arguments, use the nice man error message
10     if [ ! $1 ]; then
11         $MAN
12         return
13     fi
15     # If we have an argument that clashes with what we are wanting to be
16     # able to do, pass the whole command through.
17     for ARG in $*; do
18         case $ARG in 
19             -[dfkKwtWP])
20                 $MAN $*
21                 return;;
22         esac
23     done
25     # Make sure our cache directory exists.
26     mkdir -p $CACHE_DIR
27     # Get the man page(s) that match our query.
28     MAN_FILES=`$MAN -w $*`
29     for MAN_FILE in $MAN_FILES; do
30         # Get the name of the man file, and the section.
31         MAN_PAGE=`basename "$MAN_FILE" | cut -d \. -f 1-2 | sed 's/\./(/' | sed 's/$/)/'`
32         # Our PDF will be in this location
33         PDF_FILE="${CACHE_DIR}/${MAN_PAGE}"
35         # If we actually have a man file that matches
36         if [ -n "$MAN_FILE" ]; then
37             # See if the man file is newer than our cached PDF, and if it is,
38             # then generate a new PDF. This works even if $PDF_FILE does not
39             # exist.
40             if [ $MAN_FILE -nt $PDF_FILE ]; then
41                 $MAN -t $* | pstopdf -i -o "$PDF_FILE"
42             fi
43             # Then display the file.
44             $OPEN "$PDF_FILE"
45         fi
46     done
47 }

Tab completion and ssh/open -a

I use the Terminal just as much as the Finder, and have tab-completion turned on in bash. To make it better, you can set it so that it will complete differently depending upon what you have already typed in.

The first one of these tips will autocomplete from the ~/.ssh/known_hosts file, so that when you type in:

$ ssh ma[tab]

1 complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh

it will autocomplete the servers you ssh to that start with “ma”.

The next one is more complicated - it allows you to complete from all available applications when typing:

$ open -a [tab]

1 complete -W "$(/bin/lsregister -dump | /usr/bin/sed -E -n -e '/\/Applications/{s/^.+ ((\/Applications|\/Developer).+\.app)$/\1/p;}' | \/usr/bin/sed 's/ /\ /g' | \/usr/bin/sed -e s/\'/\\\'/g | /usr/bin/xargs /usr/bin/basename -s '.app' | /usr/bin/sed 's/ /\\\ /g')" open -a

These can be added to one of your bash startup files: mine live in ~/.bashrc.

Mac OS X Internals: A Note on Automounting MacFUSE File Systems

A Note on Automounting MacFUSE File Systems

Mac OS X, like many other Unix-like operating systems, includes the “autofs” file system layer that make automatic on-demand mounting of remote resources possible. See the man page for automount(8) for more details.

From Mac OS X Internals: The Blog » Blog Archive » A Note on Automounting MacFUSE File Systems

Awesome. This might replace the need for ExpanDrive. And be even more automatic.

NSSegmentedControl selecting NSTabView

I discovered, quite by accident the other day, that it is possible to use an NSSegmentedControl to control which Tab of an NSTabView is displayed. Here is how to do it.

First of all, it is much easier to change the selected tab if you leave the tabs on to begin with. So, I would suggest building all of the NSTabView’s tabs first. I’ve done five, each with a different control.

View1.png View2.png

Now, you can alter the NSTabView so it doesn’t show the Tabs:

View1Tabless.png TabViewInspector.png

You can now add the NSSegmentedControl, and style it as you wish. I really like the Small Square styling.


Now to hook up the connection. There is an outlet on NSTabView called takeSelectedTabViewFromSender:, which can be hooked up to an NSSegmentedControl.


You will need to ensure that your initially selected cell and view are the same index, which prohibits having it save the value between runs (or you might be able to, if you know more than me).

1Password Licenses

I have a couple of licenses for 1Password to give away. Leave a comment with your name and email if you are interested.

Mac only!

Update: all have been given away. Got quite a few responses in Whirlpool, before my thread was shut down.

iSync Menu


This stupid menu keeps appearing. I’ve turned it off several times, but it reappears.

Doesn’t seem to be every time I reboot.


iPhoto - Time to Reconsider?

Less than 12 months ago, my (effective) father-in-law bought a new Acer laptop. It came with Vista installed, and was “better than a MacBook Pro, and heaps cheaper.”

I’ve spent countless hours since then trying to get it to work smoothly. For instance, if you create a bluetooth connection to his HP printer, it prints. Once or twice. Then you need to delete the printer and re-create it for it to work. My MacBook Pro connected once, and all was good.

Another issue has been with network connectivity. He’s using a GSM USB dongle to get wireless internet, and it’s rather flaky. I plugged the same dongle into my laptop, and it worked. I can’t recall if I needed to install any software, but, and here’s the important part, if I did install a driver, it used the system’s networking stack, rather than installing another one. This is something that the PC world just doesn’t seem to get. I had to “fix” a similar problem with my sister’s machine. Using the basic Windows WiFi driver gave a much better result than the one that came with the laptop.

Finally, he decided that it was worth the effort getting an iMac. He’d then set up most of the stuff before I arrived, including the wireless internet, and all I had to do with install VMWare (and WinXP) so he can run his share-tracking program, and anything else he may have to run under Windows. Oh, and Office. I’ve got him trying out iWork, but we’ll see how that goes.

I also had to help him transfer across all of his iTunes music and photos. I’d bought my laptop with me, and had set up an ad-hoc wireless network, which I had confirmed was working. I had shared his Public directory on the iMac, and was able to connect to it from the PC, but was having trouble getting the PC share to actually appear on the Macs. Eventually I did, and copied the files across. As it turned out, I needed to change the ad-hoc network name several times as I tweaked the settings, as Windows seems brain-dead when dealing with changed network properties and the same network name. I’d hit this issue in the past when trying to connect with an old laptop (no WPA) to an ad-hoc network created by one of my machines.

I then imported all of his photos into iPhoto. Which, I discovered, is now not the clunky old program it used to be. It feels more like iTunes, but is even more snappy. It has the nice little feature of scrubbing over all of the contained images like the new iTunes view.

I think I’m going to have another try with iPhoto. I got right into Lightroom when I had a DSLR, but since I don’t take too many photos anymore, so something less high-end will do me fine.

And, I can then use the fairly cool screensaver that uses the iPhoto library to create mosaics. I’d forgotten how cool that was. I think that feature alone caused his other daughter to proclaim she too would get a Mac.