iTunes, the menu bar, unicode, and GeekTool

Jul 06, '04 09:53:00AM

Contributed by: Pausanias

I had always wanted to use the empty space on my menu bar to display the name of the tracks playing in iTuness, without my having to click on or type anything. I looked long and hard, but did not find any free apps that did this specifically. Finally, I came upon the excellent GeekTool, which many of you know of. This program allows you display information in your unused desktop space.

Using GeekTool, I created a transparent, borderless window that was exactly the height of the menu bar. I moved the window on top of the menu bar, selected the "Always on top" option, and voila! I had a setup that would always display text atop the menu bar -- seamlessly and transparently, without looking like a window at all! Then I just needed a simple AppleScript that would get the name of the song currently playing:

 tell application "iTunes"
   set foo1 to name of current track
   set foo2 to player position
   set foo3 to duration of current track
   set foo4 to foo1 & " " & foo2 & "/" & foo3
 end tell
I saved the above script as iTunesName.scpt. Then inside GeekTool, I set my menu-bar-sized window to run the following shell command every 10 seconds:
 osascript /path/to/scripts/iTunesName.scpt
Where, of course, you would replace /path/to/scripts with the location where you saved iTunesName.scpt. It worked very well, except for tracks with international characters in them. For these tracks, the special characters would come up garbled! I tried typing the above command into an xterm, and the same garbled characters came up.

After much research, I found out that for some reason the xterm program (and GeekTool) doesn't process UTF-8, the unicode format returned by AppleScript, by default. However, the program iconv, which comes with OS X, will do the trick. If you know you have tracks with special characters in them, try (shown on two lines with a continuation character):
 osascript /path/to/scripts/iTunesName.scpt | \
 iconv -f utf-8 -t ucs-2-internal
This did the trick! Characters with umlauts, accents, and so on all displayed properly, both in the xterm and in GeekTool! It goes without saying that iconv's application is not limited to iTunes -- you can use it anytime you need to display utf-8 inside an xterm. As an aside, utf-8 will display perfectly inside Apple's Terminal application.

Comments (23)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2004070301135736