Logging In and Out of Adium, iChat and Skype using AppleScript

Even though I'd rather not, I use not one, not two but three instant messaging applications on my main machine: Adium, iChat and Skype. While Adium allows to connect to almost all IM networks in a slick little interface that feels right at home on Mac OS X, iChat has some unique features going for it, for instance Bonjour as well as audio and video chat, and Skype of course is the only app that can run Skype. Besides, everyone at work uses Skype, so I just have to have it running at all time. Using all three together it not a big problem to me, at and even less of a problem since I wrote two little pieces of AppleScript that allow me to connect and disconnect from all the applications using a command-line scripts. Here are the scripts, both wrapped in an executable (chmod +x) script called either online or offline using the osascript command.

Going offline:

on IsSkypeRunning()
  tell application "System Events" to (name of processes) contains "Skype"
end IsSkypeRunning

on IsAdiumRunning()
  tell application "System Events" to (name of processes) contains "Adium"
end IsAdiumRunning

if IsSkypeRunning() then
  tell application "Skype"
    send command "SET USERSTATUS OFFLINE" script name "Make Skype go offline"
  end tell
end if

tell application "iChat"
  log out
end tell

if IsAdiumRunning() then
  tell application "Adium" to disconnect every account
end if

Going online:

on IsSkypeRunning()
  tell application "System Events" to (name of processes) contains "Skype"
end IsSkypeRunning

on IsAdiumRunning()
  tell application "System Events" to (name of processes) contains "Adium"
end IsAdiumRunning

if IsSkypeRunning() then
  tell application "Skype"
    send command "SET USERSTATUS ONLINE" script name "Make Skype go online"
  end tell
end if

tell application "iChat"
  log in
end tell

if IsAdiumRunning() then
  tell application "Adium" to connect every account
end if

Labels: , , , ,