Skype Auto Answer with AppleScript

  • Written

After discovering the ability to auto answer FaceTime, I tried my hand at adapting the script for Skype. I waited a couple of days until my girlfriend had some downtime and patience to call me over and over while I tried to debug the elements on my screen. Eventually I figured out how to select the window, and then the correct button. I did try, unsuccessfully, for a long time to select the button based on the label. If anyone knows how to do this, please leave a comment!

Continuing on, set up is much the same with only the basic code changed. Let's start again by opening up "Script Editor" and copying this snippet into the editor:

set contacts to {"Keyue Bao"}

  repeat while application "Skype" is running
    tell application "System Events"
      tell process "Skype"
        set videoCallWindow to a reference to (first window whose name is "Incoming Video Call")

        if videoCallWindow exists then
          set callerId to value of static text 1 of videoCallWindow

          if contacts contains callerId then
            click button 2 of videoCallWindow
          end if
        end if
      end tell
    end tell
    delay 2
  end repeat
  delay 5
end repeat

So, while Skype is running we try to select the incoming video call window. Of course, this window will only exist when we have a call to answer, so we check that it exists. After that, we grab the caller ID from the text element and check if it matches who we want. Then we click answer. It actually took me a few tried to figure out which index was the answer with video button as it doesn't follow visual order.

Before we export, change the caller ID. Then, go to File -> Export and save it somewhere you'll remember. I exported mine to Documents/Scripts/skype-auto-answer.

Next step, let's navigate to cd ~/Library/LaunchAgents in the Terminal and create our file using vi In vim, you'll need to press i to go into "insert" mode. Copy and paste the code below, but remember to change the script location to where you just exported to.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

And we're almost done. Let's exit vim (Esc, :wq, Enter) and get Launchd to pick up our changes.

launchctl load -w

Tada! You might need to accept the accessibility dialog that pops up, but the script will now be running. You can verify this by executing launchctl list | grep skype-auto-answer.


P.S. If you ever want to unload the script, just execute launchctl unload -w, same as you did to load.

Questions? Find me on Twitter or open an issue.