Developing an On-the-Phone AppleScript

I’m now working from home, but I can’t stand not having music going when I’m working. I often answer the phones, so it was important to me to have an AppleScript that would quickly do the following:

  1. Mute the system volume so I can focus on the customer.
  2. Pause iTunes.
  3. Setting my Adium status as On-the-Phone so my co-workers know I’m on the phone.

The fun thing is that I’ve got to get the script to do the reverse when invoked again. Otherwise, what use is it?

My first step was to use Leaf Raker’s suggestion for how to mute the system volume with AppleScript. The approach there works fine; the only issue is going to be that the system volume returns to 50 when it’s invoked a second time. If you’re always using this script during the day, though, that shouldn’t be a problem. Thanks, Leaf Raker, for getting me started!

The second step is pausing iTunes. If you read the iTunes Applescript Dictionary, you’ll see that it has a verb “playpause” that toggles the status of iTunes. This is helpful for me when I’m listening to a podcast while working, because I would like to not lose my place while I’m on the phone. So it’s tell application "iTunes" to playpause to make it happen.

The last step, of course, is the Adium status change. The Adium wiki has a page on their AppleScript support, and after a number of tests, I found that this worked:

tell application "Adium"
	set thisStatus to the status type of the first account
	if thisStatus is available then
		set the status type of the first account to away
		set the status message of the first account to
		"I'm on the phone; be with you shortly"
	else
		set the status type of the first account to available
		set the status message of the first account to ""
	end if
end tell

Now, this only works for my setup because I have the one account in Adium on this machine—Adium, for me, is dedicated to the IM support I have with work. Multiple-account setups would take some sniffing; this is done with of account "somename", rather than “the first account”. Of course, if you’re in my situation—working from home, wanting to set your status away when you’re on the phone—you probably only have one account in Adium that needs toggling. [You better not be on multiple IM channels if you’re telecommuting, or you won’t get anything done!]

The whole script is as follows:

set curVol to (get (output volume of (get volume settings)))
if curVol > 0 then
	set volume output volume 0
else
	set volume output volume 50
end if

tell application "iTunes" to playpause

tell application "Adium"
	set thisStatus to the status type of the first account
	if thisStatus is available then
		set the status type of the first account to away
		set the status message of the first account to
		"I'm on the phone; be with you shortly"
	else
		set the status type of the first account to available
		set the status message of the first account to ""
	end if
end tell

You can also download this: on-phone.scpt.

As always: shared without license and support. I’ll help if you ask questions in the comment, but I am under no obligation to get you to done. I worked to figure this one out, so you can work, too. 😉

Unlike with my Mail scripting, I invoke this with the excellent Launchbar, although I’m sure that Quicksilver will invoke it for you, too. I just put this in ~/Library/Scripts for safe-keeping.