Automatically playing/pausing Rdio based on proximity using Airlock and AppleScript

March 30th, 2011 by Richard Felix

I’ve been using Rdio to stream music from the internet during the workday a good bit lately, and the other day it occurred to me that it’d be nice if I could have my music stop when I left the office and start playing when I get back to the office.

I already use Airlock to lock and unlock my Mac based on my phone’s proximity to it, and it supports running applications or commands when you enter/leave an area, so that part was all taken care of. All I needed to do was write some scripts to play/pause Rdio and add them to Airlock. So, I rolled up my sleeves and whipped up a couple of AppleScripts.

There is one for playing and one for pausing, but they are pretty much identical, and I tried to be smart about the code, so if you aren’t running Rdio and you leave, it won’t launch and catch you by surprise when you get back.

The code and compiled applications are available for download here. You can just use the compiled applications if you want, or feel free to modify the Applescripts for your own needs.

To briefly explain the code:

I check to see if Rdio is running. If it is, I activate it and then programmatically click the Play or Pause menu item, depending on which script I’m running. Then, I switch back to the previous app that you were using.

if appIsRunning("Rdio") then
	tell application "System Events"
		tell application "Rdio" to activate
		tell process "Rdio" to click menu item "Pause" of menu "Controls" of menu bar 1
		keystroke tab using command down
	end tell
end if
on appIsRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end appIsRunning

Join our private mailing list

Get exclusive updates and insights from Sense Labs right in your inbox. (No more than twice a week)

1 comment

  1. Holy Crap! That’s AWESOME!!! I’m gonna program my toilet lid to raise on it’s own when I walk into the bathroom. I can’t freakin’ wait to go pee now. Thanks for sharing.

Leave a Comment