A fantastic little program called Proximity, will allow you to lock or unlock your Mac when you get close or too far from your computer. All you need to do is install the app and pair your bluetooth device with your computer. Lifehacker has posted a great guide to getting this to work. Follow along to get it setup on your computer as well.
Several AppleScripts have been created to help with the process of getting this app working for you. The first if the inrange script:
--tell application "iTunes" to play --This is optional; if you want to play music when you are in the proximity of your computer,
it will play ur musi--c.
Just delete the 2 minus signs in front of '--tell application "iTunes" to play' tell application "System Events" tell security preferences set require password to wake to false end tell end tell tell application "ScreenSaverEngine" to quit
The next script is the outofrange script, which will run when your device get’s out of range of the computer:
–tell application “iTunes” to pause
–again, this is optional, but if iTunes is playing, you might want to pause it; delete ‘–‘
tell application “System Events”
tell security preferences
set require password to wake to true
— start screensaver (which locks the screen)
activate application “ScreenSaverEngine”
You can also download both scripts here. The outofrange script will pause your music and lock the
computer screen. When you get back in range, your music will play again and the computer will unlock. If you are one of those people who locks their PC when they walk away, this would be very convenient to use and you wouldn’t even need to worry about locking your computer.