A while ago I came across an application called Proximity. It let's you use your bluetooth phone to notify your computer if you are near or not. "Now how," you say, "how would I use this to keep me from experimenting some techmological differences?" Well, allow me to explicate. This particular piece of software executes an applescript of your choice when your computer detects your phone, and, you guessed it, when your computer can no longer detect your phone.
So, naturally, Proximity is quite versatile. I've seen a couple example applescripts here and there, but none quite did what I wanted. So, stealing (yes, stealing) bits and pieces from all of them (and with the addition of my own little special ingredient) I frankenstiened the mother of all Proximity AppleScripts together. Ok, technically there's two scripts.
"Enough with this popcockery!" You say, "Show me the scripts!"
Wait, wait, wait! The nerve you have. I haven't even told you what these scripts do. These scripts do the following when exiting the premises of your beloved macintosh.
- Activates JackSMS
This program will detect if you computer has been unplugged or picked up, and alert you by either text-message or e-mail (including a picture of the perp if you have a macbook/pro with iSight) or *Gasp* both.
- Activates DeskShade
Not exactly necessary, it could be accomplished with another (free) program, but this will place a cool transparent lock icon on top of your desktop background and not let anyone past without a password (which you can set to be different from you default user password). Also it can record and report attempted entries.
- Pauses iTunes
This is the sexy part. The problem with all of the other scripts that I came across was that they would pause iTunes, yeah, but if you came back to your computer and hadn't been playing iTunes, your music would start playing anyway. With this script, your music will only resume playing if it was paused by the script, meaning you don't have to worry about coming home late at night only to start blasting Britney Spears (I know you like it). Techmologically, this could still happen if you were blasting Britney Spears when you walked out, but you should know better. But wait, there's more! Instead of just pausing or playing, iTunes will fade in and out! OMG! OMG! OMG! OMG!
When you come back to your computer with your phone, the opposite of everything above will happen. Also, you don't have to have Deskshade or JackSMS running all the time, because the script opens the applications when you leave, and then closes them when you come back. So, without further Abu, Paste this into Script Editor and call it something like "Lock Script"
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
And then do the same for this code, calling it something like "Unlock Script"
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