Having fun with Proximity for mac

One of the things I love about my mac is how easy it is to hack things to work the way I want.  I’m always amazed by how many easy hooks there are into system settings and native applications.

I recently stumbled upon a neat application called Proximity. Proximity detects when a selected device (cell phone, wireless mouse, etc) comes in or out of bluetooth range and executes selected scripts. Since my iPhone is almost always with me, I decided to write a couple scripts to password protect my laptop when my iPhone isn’t around, and unlock it when I return. As an added bonus, my code also mutes my audio and sets an away message on iChat when I leave. It then sets my status to “available” when I return.

The cool thing about this is that it keeps my laptop secure without having to mess with a screen-saver password all the time. I can think of a lot of other uses for this technology. For example, I wonder how many people would like to have a notification pop up when their boss is about to walk into the room, or just have a bluetooth device automatically sync when it’s in range of their computer. I should add that Bluetooth detection has its limitations, particularly because the underlying hardware makes it tough to detect realtime changes causing a significant lag. You also don’t have anyway to detect the strength of the signal to get any sense of how far away the device is from your computer — it’s entirely binary — the device is on and in-range or it’s not. That said, it’s still a powerful demonstration of what can be accomplished with technology when you start getting creative.

Here are my scripts. First, the one that gets executed whenever my iPhone goes out of range:

-- mute volume
set volume with output muted

-- set status to away
tell application "iChat"
    set status to away
end tell

-- turn on the screen saver password
tell application "System Events"
    tell security preferences
        set properties to {require password to wake:true}
    end tell
end tell

-- activate the screen saver
tell application "ScreenSaverEngine" to activate

-- if the above line doesn't work, try uncommenting this instead:
-- do script "/System/library/Frameworks/Screensaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine"

And, in range:

-- set status to available
tell application "iChat"
    set status to available
end tell

-- disable screen saver password
tell application "System Events"
    tell security preferences
        set properties to {require password to wake:false}
    end tell
end tell

-- turn off the screen saver
tell application "ScreenSaverEngine" to quit

Let me know if you come up with any other applications for this or have suggestions for other functionality I should add to my fancy phone-triggered security system.

  • http://intensedebate.com/people/julien julien

    Downloading this thing right now! That looks like something I've been dreaming for for years!

    • http://intensedebate.com/people/joshfraser Josh Fraser

      Let me know if you come up with any neat applications for it.

      • http://intensedebate.com/people/julien julien

        I've played with it and I find it sad that I can just add one device at a time. I mean, I'd define home with the fact that ihave my BT mouse and keyboard…

        • http://intensedebate.com/people/joshfraser Josh Fraser

          I found that limiting as well. Considering that it's open source, one of us could fix that. :)

  • OpenSEO

    What will happen if you loose your iPhone, or worse ? or just dead battery ?

    • http://www.onlineaspect.com Josh Fraser

      I will just have to enter my password. No biggie.

  • http://intensedebate.com/people/ignighter36531 Kevin Owocki

    Neat implementation. Reminds me a lot of the home automation kits I used to buy a few years back. I'm going to try it out.

  • http://www.facebook.com/wlsn.chrs Chris Wilson

    Anyone figure out how to get this to work with Snow Leopard? The login windows just appears black and the login prompt doesn't appear until after a restart.

    • http://www.facebook.com/joshfraser Josh Fraser

      It's on my todo list to try and look into that issue. I haven't had time to figure it out yet. If you beat me to it, please let me know!

    • http://intensedebate.com/people/jud_valeski3968 Jud Valeski

      seeing this too.

  • Kyle Kuczun

    The following should solve the in_range.scpt issue in snow leopard with respect to the login…

    <snip>

    do shell script "defaults -currentHost write com.apple.screensaver askForPassword -int 0"

    — turn off the screen saver
    tell application "ScreenSaverEngine" to quit

    set output to do shell script "defaults -currentHost read com.apple.screensaver askForPassword -int"

    <snip>

  • Calven

    This is fantastic stuff!!!

    I've paired this with my iPhone at work and now i can leave my Mac without ever having to set the screensaver or turn the music off.

    I can think of many new uses for this.

  • Nick

    just need a bluetooth device in my home train station so my iPhone can wake me up after a night out when i approach the station, so i don't oversleep and wake up at the end of the line… yet again.

    • http://www.onlineaspect.com Josh Fraser

      until then, how about just looking at the schedule and setting a timer to go off right before you're scheduled to arrive?

    • Bart

      Have a look for an application to detect WiFi networks in range, and executes a script when the railway station hotspot gets in range