da: (bit)
[personal profile] da
I want my work mac to lock, with password, when I'm away from it, but I'm not too keen on typing in the password when I come back. I've gotten my home desktop to do The Right Thing. The tricky part is unlocking without password, since that's not a standard feature of OS10.4 or 10.5.

To replicate, you need: mac with bluetooth, phone with bluetooth, BluePhoneElite (shareware, $25, boatloads of features I find useful [edit to add: if you don't want the other features, this free donationware script will do the trick], and Mac Development Tools installed.

Steps:
1) Open Script Editor, start a new script, and paste in this script:

------------------------------------------------
-- ABOUT phone-proximity
------------------------------------------------
-- This script displays a dialog when a phone enters or exits Bluetooth range.

------------------------------------------------
-- REQUIREMENTS
------------------------------------------------
-- This script can be added to the "Bluetooth Phone In-Range" trigger.


------------------------------------------------
-- SAMPLE CODE
------------------------------------------------

-- tell AppleScript where to look for the dictionary when it compiles the script
using terms from application "BluePhoneElite 2"

-- set up a handler for any bluetoothphone inrange event
on bluetoothphone inrange thePhone with event theEvent

if theEvent is "entered" then
-- display alert (name of thePhone) & " entered range."
-- Disable the screen Saver Password
do shell script "defaults -currentHost write com.apple.screensaver askForPassword -int 0"
do shell script "~/bin/notify"
tell application "iChat"
set status to available
end tell
tell application "iTunes"
play
end tell
-- Turn OFF the screen saver
tell application "ScreenSaverEngine" to quit


else if theEvent is "exited" then
-- display alert (name of thePhone) & " exited range."
tell application "iChat"
set status to away
end tell
tell application "iTunes"
pause
end tell
-- Turn on the screen saver password
do shell script "defaults -currentHost write com.apple.screensaver askForPassword -int 1"
do shell script "~/bin/notify"
-- Activate the screen saver
tell application "ScreenSaverEngine" to activate
end if

end bluetoothphone inrange

-- set up a handler for only the "exited" bluetoothphone inrange event
-- on bluetoothphone inrange thePhone with event "exited"
-- display alert (name of thePhone) & " exited range."
-- end bluetoothphone inrange

end using terms from


Save that script with a descriptive name, perhaps in /Library/Scripts.

(the source for this script was a sample script included with BluePhoneElite, modified with information here about changing status in iChat, and here about enabling and disabling the password-protected screen lock.)


2) Compile the short C program here, with the provided instructions. I stashed the executable in ~/bin/notify

Now's a good time to test the applescript, perhaps with this sample code.

But beforehand, start playing music in iTunes, for fuller effect.

Paste this into a new Script Editor window, then choose "run":


tell application "iChat"
set status to away
end tell
tell application "iTunes"
pause
end tell
-- Turn on the screen saver password
do shell script "defaults -currentHost write com.apple.screensaver askForPassword -int 1"
do shell script "~/bin/notify"
-- Activate the screen saver
tell application "ScreenSaverEngine" to activate

delay 10 -- seconds

-- Disable the screen Saver Password
do shell script "defaults -currentHost write com.apple.screensaver askForPassword -int 0"
do shell script "~/bin/notify"
tell application "iChat"
set status to available
end tell
tell application "iTunes"
play
end tell
-- Turn OFF the screen saver
tell application "ScreenSaverEngine" to quit



It should set your iChat status to "unavailable", turn off your tunes, and start the screensaver. 10 seconds later, it will stop the screensaver, turn on the tunes, and set your iChat status to available.

While the screen-saver is running, if you move the mouse, it will ask for your password, and not unlock without it. When the timer's up, it should restore without a password (though, this sometimes got funky and didn't happen). The following proximity stuff seems to fix the problem though.


3a) If you don't want BluePhoneElite's other features, follow the rest of the instructions here to install the freebie proximity script.

3b) If, like me, you wanted to download all your text-messages off your phone when the memory filled up (instead of deleting them), you'll probably want BluePhoneElite. Give it an install (the trial is free for two weeks). Do the install-related tasks, such as pairing it with your phone. Next, handle the proximity detector: go to Preferences->Triggers and select "Bluetooth phone in range". On the right-hand side, hit the plus, add an "applescript reactor" (in the Notification sub-menu). They have a docs page which shows pictures of the general process.

Click the gear on the right; provide the filename for the AppleScript you previously saved.

It's a good idea to check the "filter" box at the bottom, and Edit Filter to choose the phone you just added. I don't know what happens if someone else's phone comes into range, but you don't want just any phone unlocking it.

And that seems to be it. I've done a bit of testing, and it seems to work consistently. I am curious whether this bluetooth activity will suck my phone's battery much faster, though.

Re: Snow Leopard

Date: Monday, 26 October 2009 02:33 am (UTC)
From: [identity profile] da-lj.livejournal.com
Nope; I don't have a snow leopard machine to test on, yet.

I wonder if this might provide the answer: set the delay before it requires a password, either to "immediately" or "24 hours." Though, it looks like it requires a logout to take effect. Hm. Let me know if that works...

Re: Snow Leopard

Date: Monday, 28 February 2011 06:25 am (UTC)
From: (Anonymous)
Have you managed to test this on Snow Leopard yet? The notify app works for me as expected, the problem I have is that if I change the setting and call notify when the screen saver is running, instead of expected behaviour I am presented with a black screen when the screen saver is told to quit (at which I must type my password in to unlock). So it is no longer displaying the enter password box, but it won't let me proceed without it either. Very strange...

December 2024

S M T W T F S
12 34567
891011121314
15161718192021
22232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Wednesday, 24 December 2025 05:45 pm
Powered by Dreamwidth Studios