Saturday, January 6, 2007

A cute desktop clock for OS X

One of the reasons I love OS X so much is that it makes it so easy to do cool things with Unix. In today's post I'll show how I made a desktop clock using GeekTool and the date command. GeekTool is an OS X application that will render text files, images and shell command output into the desktop. Its website isn't really updated a lot, but it still works, and if it doesn't, its source is out there. I guess it got mostly superseded by the widgets of the Dashboard, but it renders into the desktop, which Dashboard won't do without some hacks. (Although that might change next week if/when Leopard comes out :-) ) I also used this great free font I found, Atomic Clock Radio. To set it up, I created a rounded background (using The Gimp of course), and told GeekTool to put that on the right side of my screen with a pleasing opacity (in the style tab).
Then I added the output of the command date "+%H%n--%n%M", updating every 20 seconds, in another item and told it to render with the Atomic Clock Radio font. That command renders a 24h clock with embedded newlines. The dashes looked most pleasing. Experiment, it's easy.
That's all there is to it. Simple tools with big impact, that's how I like my Unix ;-) You can get the background image I used here. It's rounded on all sides, so you can choose where you put your clock.

Tuesday, January 2, 2007

Control iTunes over SSH

So I was looking for a good way to control iTunes running on my Mini mac at home. There's some payware options, like netTunes and webRemote, and some freeware options, like zTunes and iTRC. I kind of prefer using open source if I can get it, so I am giving the payware options a miss for now. Unfortunately none of the freeware options are cross-platform and secure at the same time. On top of that, most of the them are quite buggy. So while I wait for zTunes to become faster, less buggy and more secure, I chose the third option, which is Write Your Own :-) Thanks to the wonders of Applescript, iTunes is very accessible from other programs. You can basically get information about anything in your library and perform almost all the actions that you can perform from the program itself. So I wrote a remote control in bash, to be accessed over SSH. I present to you iTunesCLI 1.0. To use, save this script where you can find it again on the system that you want to use it from, for example in your home directory or in /usr/bin. Make it executable with chmod +x Then ssh to that system and run the script:
ssh -t mysystem ./iTunesCLI (when stored in your home directory)
ssh -t mysystem iTunesCLI (when stored in /usr/bin)
The -t option is needed to make keystrokes be recognized immediately. SSH tips:
  • Use an SSH agent so you don't have to type your password every time. For OS X, try for example SSH Keychain
  • The hostname for the remote machine is most likely machinename.local. For example, my Mac Mini is hooked up to the stereo and is called mini-me. I just run "ssh -t mini-me.local iTunesCLI".
I had to come up with some nifty tricks to make it fast and pretty. Look at the script file to see bash arrays, IFS swizzling, printf builtins, tput abuse, multiline commandlines embedded in backticks and a mangled model-view-controller concept, oh my! I sprinkled it with comments in the hopes of making it maintainable :-) Enjoy!