Automatically restart applications on OS X

I use GimmeSomeTune to provide hotkeys and some other goodies for iTunes. It works alright, but is veeeery crashy — usually every dozen hours or so on my machine.

How to fix that? Let’s relaunch it as soon as it crashes. Simple!

In a terminal:
for (( ; ; )); do open -W /Applications/Multimedia/; done

open is the bash command to launch applications on OS X. It works with all kinds of files: open somefile.avi will open that file in your default video player, VLC for example. The -W flag tells open to wait until the application exits before returning any value. By putting it all in a for loop, we effectively ensure that bash will launch GimmeSomeTune, wait until it crashes, then relaunch it, and so on.

Edit: this is a bad way of doing things. A better way is described here.

A bit of Terminal-fu

Yesterday, my little brother was typing something on a linux bash and suddenly went back to the beginning of the line with a simple Ctrl-a. It blew my mind.

I don’t know why, but it never occurred to me to look for shortcuts in Terminal (and bash in general), other than Ctrl-c for badly behaving processes. I just cursed myself and frantically typed on the left arrow key each time I typed cd instead of cp.

Turns out bash has plenty of them, and here are a few useful ones I’m really glad to know now:
Beginning of the line: Ctrl+a
End of the line: Ctrl+e
Delete the word under the cursor or before: Ctrl+w
Delete all chars before the cursor: Ctrl+u
Delete all chars after the cursor: Ctrl+k

Apparently these shortcuts work in a lot of text fields, everywhere.

You can also move the cursor word-by-word by typing Esc, then f or b. It’s not really practical though, so you’d be better of remapping the following keys in Terminal Settings > Settings > Keyboard:
control cursor left: \033b (\033 is actually Esc)
control cursor right: \033f

Now you can swiftly move word-by-word with Alt+left arrow and Alt+right arrow.

I guess the lesson here is there’s always to learn from your siblings — especially the geeky ones.

A keyboard shortcut to change files colours in the Finder?

My usual habit (some would call it an intermittent OCD, but meh) of sorting and organizing files and folders to a great extend and my almost as severe relentless longing for optimisation recently met in an existential question: is it possible to colour files in the Finder through a keyboard shortcut?

OS X lets you add colours -or “labels”– to a file by right-click or in the Finder’s File menu. GUI are cool, but get in the way of efficiency once you know your keyboard inside and out.

Well, after some research, it seems that such a shortcut does not exist. You can’t even create a shortcut the usual way, as the “Label” menu point stands for all labels. (I’ll eventually describe the usual method in this blog!)

The simplest way to implement such a feature was to create a set of AppleScripts that colour files that are currently selected, and launch them via the most amazing QuickSilver. Or Alfred. Or even Spotlight.

The AppleScripts look like that:

property file_color : 5
-- replace '5' above with the number for the color you'd like to use:
-- 0=none, 1=orange, 2=red, 3=yellow, 4=blue, 5=purple, 6=green, 7=grey 

tell application "Finder"
	set items_ to selection
	repeat with item_ in items_
			set label index of item_ to file_color
		on error e
			display dialog e
		end try
	end repeat
end tell

This is the purple one. Therefore, I called it scp_SetColourPurple.scpt and dropped it off somewhere QuickSilver indexes – proceed this way for each colour you want to add.

All it takes now to colour a set of files is to select them in the Finder, type in Ctrl+Space (to summon QuickSilver) and the three letters to your colour of choice – scp to set the coulour to purple, scr to set colour to red, scy to set colour to yellow…

(Full disclosure: the above code was originally found somewhere on the internet, I can’t find where right now. If I find the link again, or if someone can point it to me, I’ll give props to the original author.)

Seitunes 1.0

Seitunes v1 is here! I think everything I need it to do is in here. I’m not planning on adding new features in the near future – if anything, I’ll concentrate on optimizing performance.

Sei what?

Seitunes is a command-line interface for iTunes.

It allows you to see what’s playing in iTunes and control it (play, pause, set volume, toggle shuffle, select a playlist, set song rating) from your terminal.

Overview of v1.0

I finally decided to split the program in two separate parts.

libseitunes.(c|h) is a C API to access iTunes through Applescript calls. It is also under GPL.

Seitunes.(c|h) is the higher-level part of the application, which is now completely Applescript-free.

New Features

Support for rating (display and modification).

Playlists: Seitunes now displays the playlist currently playing. You can also see all available playlists, and select the one you want to play (with ‘/’).

Bug fixes

A bug caused Seitunes to think iTunes was completely stopped (hence not displaying data about artist and song) if you went to next track whilst playback was paused. iTunes actually reports such a condition as “stopped”, so I added some code to handle this case (it basically checks if there is a “current track”, and if so, displays the data).


Seitunes is now on GitHub!


I’ve stumbled upon this very interesting blog post by Eric Sink, classifying software into three big categories: ThemWare (someone writes software, only other people use it), MeWare (someone write software, only he uses it) and UsWare (someone writes software, he uses it and other people do so).

I have currently no idea if anyone else uses Seitunes, or even downloaded it once to see. If you do use it, I’d be delighted to hear from you!

Fix ncurses in OS X 10.6.3

In response to my blog post about the issue affecting arrows under OS X 10.6.3, Jonathan Groll pointed out that copying the ncurses libraries from an old 10.6.2 install would fix the problems. It works, but manipulating libraries in that way still feels a bit wrong to me.

And that’s without even mentioning the security implications of getting these libraries from “somewhere on the internet” if you don’t have them laying around anymore.

Instead, let’s fix an Open Source system in the way Open Source is supposed to work: grab the sources and recompile!

Grabbing the sources

Apple provides the sources for the insides of OS X on Considering ncurses-31 (the 10.6.3 version) is buggy, we’ll download a tarball of ncurses-27 (the 10.6.2 version) from Apple right there: ncurses-27.tar.gz.


Step 1: compile.

mbp:ncurses-27 florent$ make

Step 2: install.

mbp:ncurses-27 florent$ sudo make install
TargetConfig: MacOSX
cd /tmp/ncurses/Build && CFLAGS="-arch x86_64 -arch i386 -arch ppc -g -Os -pipe -isysroot /" CCFLAGS="-arch x86_64 -arch i386 -arch ppc -g -Os -pipe " CXXFLAGS="-arch x86_64 -arch i386 -arch ppc -g -Os -pipe " LDFLAGS="-arch x86_64 -arch i386 -arch ppc            "  /tmp/ncurses/Sources/ncurses/configure \
		--prefix=/usr --disable-dependency-tracking --disable-mixed-case \
		--with-shared --without-normal --without-debug --enable-termcap --enable-widec --with-abi-version=5.4 --without-cxx-binding --without-cxx --mandir=/usr/share/man
/bin/sh: line 0: cd: /tmp/ncurses/Build: No such file or directory
make: *** [install] Error 1

Oookay, by default this Makefile tries to install ncurses into /tmp/ncurses and complains because the directory doesn’t exist. Why not. There has to be an option to change that when calling make, but I went for the fastest choice:

mbp:ncurses-27 florent$ mkdir /tmp/ncurses/Build
mbp:ncurses-27 florent$ sudo make install

And wait for the magic to happen. It’s quite long (and verbose) actually, don’t worry if it takes a few minutes.

Once this was finished, I launched sudo update_dyld_shared_cache and ran some tests: no luck, ncurses still behaved badly.

Then I noticed the “make install” output seemed to show ncurses-27 was actually installed (great!)… In /tmp/ncurses (not so great).

Making it (actually) work

I don’t fully understand how OS X deals with these source tarballs. However, I noticed that /tmp/ncurses/Build contains a Makefile. It looks like what’s installed in /tmp/ncurses is merely an intermediary build that you can then install:

mbp:ncurses-27 florent$ cd /tmp/ncurses/Build/
mbp:Build florent$ make
mbp:Build florent$ sudo make install

I then ran sudo update_dyld_shared_cache again. This time, it prompted:

update_dyld_shared_cache[62767] current i386 cache file invalid because /usr/lib/libncurses.5.4.dylib has changed
update_dyld_shared_cache[62767] current x86_64 cache file invalid because /usr/lib/libncurses.5.4.dylib has changed

Which is good, because it shows we actually changed the compiled version of ncurses (libncurses.5.4)

I finally ran the tests again: ncurses now works like a charm!