--Applescript to stop Skype from calling back on disconnect

--On Mac OS X, since version 5.x, Skype attempts to call back if the call is disconnected due to network problems or any other reason other than a hang up. This can be extremely annoying and I found no way to circumvent it by blocking a particular outgoing port. Sometimes I want to diconnect a call quietly, so I disrupt the network, or, find Skype's pid (let's say for this example, it's 549) and do "kill -STOP 549; sleep 17; kill -CONT 549" in Terminal. 17 seconds seems to be long enough to reliably disconnect a call, and it happens on the other end quietly, without the noise of a hang up.

--Below is an applescript which you can start after connecting to another party. Be sure to quit the script if you no longer want Skype to be killed when the call ends. This isn't a very elegant solution, but I just needed something quick and it works well enough for my purposes. It uses the Skype AppleScript API to get the id number of the Skype call, and if that call is no longer active, it kills Skype. The script checks Skype every second, and that seems to be often enough so Skype doesn't have a chance to ring the other party before it's killed. Hopefully Skype will have this "feature" made into an option, but until then, or until I do more research and find some better way to do it, I have this script.

--If you want to use the script, open Script Editor, paste the text below into a new script, then Save the script as file format Application, with the "Stay open after run handler" option checked. Then double click that script once the call has started. Skype will be killed if the call disconnects. Note that your Skype will go offline, which might make a "user going offline" noise on the other end (though Skype doesn't always notice when another user goes offline and comes back on quickly) but that won't happen if you're also signed in on a smart phone or something.


global thecallid, skypepid, thefirst
set thecallid to ""
set thefirst to true
set thecommand to "ps ax | grep Skype | grep -v grep | awk '{ print $1 }'"
set skypepid to do shell script thecommand
on idle
	set theDelay to 1
	tell application "Skype"
		set theResult to send command "SEARCH ACTIVECALLS" script name "skypekill"
		set theStatusWords to every word of theResult
		set theStatusList to {}
		repeat with eachWord in theStatusWords
			if eachWord as string ≠ "CALLS" then
				set end of theStatusList to eachWord as string
				if thefirst then
					--assuming there's only one active call when script is launched
					set thecallid to eachWord
				end if
			end if
		end repeat
	end tell
	if (thecallid as string) is in theStatusList then
		if thefirst = true then
			set thefirst to false
		end if
	else
		if not thefirst then
			set thecommand to "kill " & skypepid
			do shell script thecommand
			continue quit
		end if
	end if
	return theDelay
end idle

on quit
	continue quit
end quit
--For the curious, there are a number of reasons people don't like this behavior. Some people talk to their loved ones at bedtime, and when the other party falls asleep, they don't want a network problem to initiate a call back which will wake the sleeping person. Others use Skype as a baby monitor, and don't want to wake a sleeping baby if the call disconnects. If you are observing a meeting, you may not want to call back while someone is talking, but rather discreetly notify someone at the other end to call you back. Others have had problems where both Skype clients automatically attempting to call back at the same time causes a failure.

-- linux macosx hints etc page