Having switched to the Mac for my work environment, I missed some of the built in scripting that Linux offers natively. Turns out, the Mac offers this too. There are a few minor hurdles to clear in order to start scripting on the Mac. The trick is the interplay between AppleScripting and shell scripts.
My problem was that iChat wasn't waking up after resume from sleep. You may say, "Use Adium!" But Adium crashes and crashes, and doesn't let me add new contacts. Tried the beta, etc.
So I wrote a script which logs into iChat and sets status to "available" that runs on resume from sleep.
First off, install MacPorts.
Next, sudo port install sleepwatcher
Sleepwatcher is invoked in daemon mode to run a command on wake, sleep, or other things. Check out the man page: man sleepwatcher It's pretty powerful.
In order to find out more about the commands that iChat would accept, I created a shortcut to Applescript editor (it's under Utilities) on the dock, then dragged iChat onto it, which revealed the Applescript Dictionary for that program. I tested this:
#!/bin/sh
osascript -e 'delay 10
tell application "iChat"
log in of service "youruseraccount"
log in of service "yourotheruseraccount"
set the status to available
end tell'
save as /path/to/wake.sh
Now, set up an Applescript to run that script. Paste in this code:
do shell script "/opt/local/sbin/sleepwatcher -w /path/to/wake.sh &> /dev/null &"
Compile it, then save it as an application. This program runs the AppleScript app you've created as an background process and runs the terminal command also. In this way you can add it as a login item.
Go to System Preferences -> Accounts -> Login Items and add it there.
Done. Now, ten seconds after login, iChat will log in and set status to available.