Skype mood message countdown on the Mac

Posted by Patrice Neff Tue, 09 Jan 2007

I’m currently counting down to one of the most important events in my life. Most of my friends by now know what I’m talking about. But I always forgot to update my Skype mood message – that’s where my friend circle counts days nowadays.

The following 8-line Ruby script takes the problem away from me.

#!/usr/bin/env ruby
deadline = Time.local(2007, 01, 20, 22, 05)
seconds = deadline - Time.new
days = (seconds / 60 / 60 / 24 * 1000).round / 1000.0
cmdline = "osascript " +
  "-e 'tell application \"Skype\"' " +
  "-e 'send command \"SET PROFILE MOOD_TEXT " + days.to_s + " days left\" script name \"Countdown\"' " +
  "-e 'end tell'"
`#{cmdline}`

Save that and put the following into your crontab (accessible with crontab -e on the command line):

*/2 * * * * /Users/pneff/bin/skype-countdown.rb

Of course you can change both the time difference and the rounding.

The event I’m counting down to occurs on January 20 at 22:05.

The only thing that needs explanation is the invocation of the osascript command. That’s a command line tool that OS X provides to execute Apple Script. The whole thing could also be programmed in AppleScript, but Ruby is my script language of choice – and this way I was able to do that in five minutes – less time than it took to document that here.

To get started with the Skype API for AppleScript, see Skype AppleScript API (just a short intro) and the Skype API reference.

Thanks to Apple and Skype for providing such interfaces.

blog comments powered by Disqus