Skype mood message countdown on the Mac
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.