applescriptskypeicons.jpgIf you use Skype and happen to be as clumsy as I am, you may have run into this at some point: you see a call come in, you fumble for your headset, you go back to your mouse, find the cursor on your big screen and then try to click the “Answer” button on the call window… only to miss the call because you took too long. I solved this for myself a while back, and thought I’d share my solution.

It’s a fairly simple AppleScript that requires nothing but Skype. It will make good use of Growl if you have it installed, but it’s only needed for visual feedback; the script will function fine without it. I use Spark to trigger it, but you can use any kind of launcher that can run AppleScripts. If Spark isn’t your cup of tea, definitely check out FastScripts. Ultimately, you just need to assign the following script to a hotkey…

The script

global _proc
global use_growl

tell application "System Events" to set _proc to name of processes as list
if _proc contains "GrowlHelperApp" then
	set use_growl to true
	my growlRegister()
else
	set use_growl to false
end if

if _proc contains "Skype" then
	tell application "Skype"
		set calls to send command "SEARCH ACTIVECALLS" script name "AnsweringScript"
		set callID to last word of calls
		if callID is not "CALLS" then
			set status to send command "GET CALL " & callID & " STATUS" script name "AnsweringScript"
			if last word of status is "RINGING" then
				send command "ALTER CALL " & callID & " ANSWER" script name "AnsweringScript"
				my growlNotify("SkypeAnswer", "Answering call")
				return
			else
				send command "ALTER CALL " & callID & " HANGUP" script name "AnsweringScript"
				my growlNotify("SkypeAnswer", "Hanging up")
			end if
		else
			my growlNotify("SkypeAnswer", "No call found to answer or hang up")
		end if
	end tell
else
	my growlNotify("SkypeAnswer", "Skype not detected")
end if

using terms from application "GrowlHelperApp"
	on growlRegister()
		tell application "GrowlHelperApp"
			register as application "SkypeAnswer" all notifications {"Alert"} default notifications {"Alert"} icon of application "Skype.app"
		end tell
	end growlRegister

	on growlNotify(grrTitle, grrDescription)
		if use_growl is true then
			tell application "GrowlHelperApp"
				notify with name "Alert" title grrTitle description grrDescription application name "SkypeAnswer"
			end tell
		end if
	end growlNotify
end using terms from

Open this script in your Script Editor

In an app like Spark, I can just paste the source into a new command and assign a hotkey. If you’re running a launcher that needs file input, just open the source in your AppleScript Editor and save it as an .scpt file, then point to that.

The script basically looks at current calls in Skype, and if a call is ringing or in progress, it takes the appropriate action (answers if it’s ringing, hangs up if it’s in progress). If no calls are happening, it will just exit (with a little whimper via Growl). Put it on an easy-to-hit keyboard shortcut and you’ll be able to grab your headset and answer a call faster than, well… faster than I’ve ever managed to without it.