I wanted to have my macbook automatically lock and unlock based on if I am in the room or not automatically. Best way to do that I figured would be bluetooth, since I always have my phone on me, and it has bluetooth. From there I proceeded to google.
http://web.mac.com/jhollington/technocrat/The_Technocrat/Entries/2007/3/18_Bluetooth_Proximity_Detection_on_OS_X.html
Pointed me to
http://www.apple.com/downloads/macosx/system_disk_utilities/proximity.html
he also includes a script to automate syncing your phone book and such too
Another utility in my searching, is called JackSMS
http://www.macupdate.com/info.php/id/21860
JackSMS does some cool stuff like, say someone tries to access your laptop while you’re not there – the built in isight camera will take their picture and email it then, so I wanted to use JackSMS as well.
Proximity allows you to set scripts for when you arrive or when you leave, so here are the applescripts I used:
lock.scpt:
tell application "JackSMS" to set lock screen to true
unlock.scpt:
tell application "JackSMS" to set lock screen to false
courtesy of: http://www.macosxhints.com/article.php?story=2006061914363693
update: a better proximity script, copied below, courtesy of:
http://pixelignition.net/better-proximity-applescript
lock.scpt:
Show ▼
global okflag
set okflag to false
set front_app to (path to frontmost application as Unicode text) -- So we can switch back to this after running the fade
-- check if iTunes is running
tell application "System Events"
if process "iTunes" exists then
set okflag to true --iTunes is running
end if
end tell
if okflag is true then
try
tell application "iTunes"
set currentvolume to the sound volume
if (player state is playing) then
repeat
--Fade down
repeat with i from currentvolume to 0 by -1 --try by -4 on slower Macs
set the sound volume to i
delay 0.01 -- Adjust this to change fadeout duration (delete this line on slower Macs)
end repeat
pause
--Restore original volume
set the sound volume to currentvolume
exit repeat
end repeat
set comment of current track to "Proximity Paused"
end if
end tell
tell application front_app
activate
end tell
on error
beep
end try
end if
tell application "JackSMS" to set jack status to "on"
delay 1
tell application "DeskShade"
lock
end tell
end run
unlock.scpt:
Show ▼
tell application "ScreenSaverEngine" to quit
tell application "DeskShade"
unlock
quit
end tell
tell application "JackSMS"
quit
end tell
global okflag
set okflag to false
set front_app to (path to frontmost application as Unicode text) -- So we can switch back to this after running the fade
-- check if iTunes is running
tell application "System Events"
if process "iTunes" exists then
set okflag to true --iTunes is running
end if
end tell
if okflag is true then
try
tell application "iTunes"
set currentvolume to the sound volume
if comment of current track is "Proximity Paused" then
set comment of current track to ""
play
repeat with j from 0 to currentvolume by 2 --try by 4 on slower Macs
set the sound volume to j
end repeat
end if
end tell
tell application front_app
activate
end tell
on error
beep
end try
end if