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.

Date: Monday, 4 August 2008 01:07 am (UTC)
From: [identity profile] http://users.livejournal.com/merle_/
So it's like a key: all we have to do is grab your phone and your computer can be unlocked?

(it's still very cool, I just wonder at the disabling of work security even though I suffer through my computers getting locked several times a day)

Date: Monday, 4 August 2008 01:55 am (UTC)
From: [identity profile] da-lj.livejournal.com
Yes. On the other hand, my work computer has physical security on its side; it's in a private office which is usually locked when I leave it. This measure is mostly for when I go to refill my water-bottle, and I get distracted by a conversation, and discover my office has unexpectedly been open for 15 minutes.

So, yes, like much of what I do human invention, this is born of sheer laziness.

Date: Monday, 4 August 2008 02:05 pm (UTC)
From: [identity profile] ng-nighthawk.livejournal.com
Out of curiosity, how long do you think it will take before you break even on time to develop vs. time/annoyance saved?

Date: Monday, 4 August 2008 04:01 pm (UTC)
From: [identity profile] da-lj.livejournal.com
Well, the best answer I can give is never; or immediately.
The work situation is such that it's additional security, not replacing an annoyance (we do not have a policy on locking terminals).

But in this case I don't care about the zero-sum calculation. I learned a few things and had fun in the process. I spent about 2 hours on this yesterday, including writing it up. And about 30 minutes thinking about this response, because my initial reaction was a fairly grumpy justification toward hacking, which I know you don't need to read. (Yes, occasionally [livejournal.com profile] melted_snowball rolls his eyes at the things I find fun...)

But watching my reaction, I think I should rely more on saying "I had fun, and I shared it with the hope other people would think it was fun too." No justification needed. :)

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 03:42 pm
Powered by Dreamwidth Studios