Lock Your Mac and PC with an Android Phone
I've recently written an article about how you can get an iPhone to act as a proximity lock for your Mac, but since a lot of my friends have asked me if you can do the same thing with other kind of smartphones, I've decided to describe how one could use an Android phone for the same purpose. Furthermore, this time I will offer solutions for both Macs and Windows PCs.
In case you haven't read the story I mentioned earlier, here's what we are talking about: constantly pressing the right key combination to lock your computer as soon as you leave the room, then typing your password when you return can be a bit of hassle. Furthermore, if you leave in a hurry you might even forget to lock the PC before you leave, thus opening the door for other people nearby to take a peek at your files or who knows what else. However, there's a much simpler way to preserve your privacy. You can use your Android phone to automatically lock your PC and Mac when you leave their vicinity.
The way this works is pretty simple: you pair the two devices (the smartphone and the computer) and then as soon as the Android gadget is out of connection distance, the computers will get locked. When your phone comes back into the selected range, your desktop or laptop will automatically unlock themselves. No more worrying about prying eyes, no more typing in lengthy passwords.
Windows - BTProx
BTProx is a simple application that you can get for free. Furthermore, this tool is an open-source project so if you're into coding, you can even modify it to better suit your needs. Using this application is very easy, but you need to remember that you need a PC which supports Bluetooth connections, otherwise all you're doing will be in vain.
Once you have downloaded and installed the application, simply run it and a small window will open. The first thing you need to do is click on the three dots (...) that correspond to the User device section and pair the computer with your smartphone. After the devices have been successfully connected, you will taken back to the main window where your next task will be determining the amount of time that you need to be away in order for the application to automatically lock the computer. By default this is set to 5 minutes, but let's be honest - that's way too long. I would suggest something moderate like 30 seconds, but if you are a really private person, you can select a shorter time interval. You can do so by changing the value in the Timeout section. Additionally, you can also choose to execute custom scripts whenever your PC locks or unlocks, but that's only if you wish to give it a more personal note (only works with batch files and Pearl scripts).
As soon as all your settings are complete, you close the BTProx window as the program will keep residing in the system tray and automatically lock your computer when it can no longer connect to your Android device via Bluetooth. The downside of this app is that the Bluetooth connection range isn't exactly small, so you will have to get pretty far away (fast) in order for this solution to be effective.
Mac - Proximity and AppleScript
Locking your Mac with an Android Phone is a bit more complicated than doing it with an iPhone, but still manageable. In order to accomplish this goal you will need to use an app that should already exist on your Mac called AppleScript (you will probably find it under the name of AppleScript Editor) and a third-party tool called Proximity. The second mentioned application is used to monitor Bluetooth connections and trigger specific commands whenever a device enters or exits the connection range. Unfortunately, the tool doesn't have automatic locking and unlocking functions created by default, but I'll help you overcome this problem. Basically, what we are going to do is use Proximity to pair your Android device with your Mac, then generate two scripts (one to lock and the other to unlock your screen) with AppleScript and finally put the two together so that when your smartphone is out of Bluetooth range the Mac will automatically lock itself.
So, let's start from the beginning. Click on the link I provided to download and install the tool called Proximity. (It's an open source project so it won't cost you a dime.) Now go to System Preferences, click on the Bluetooth section and pair your mobile device with your Mac. Once that's done, open Proximity's preferences window, change the device monitoring checking time to 10 seconds and press the check connectivity button to verify that everything works as it should be. Now it's time to create the scripts that will lock and unlock your screen.
Launch the AppleScript application (you can use the finder to get to it quicker) and create two scripts. For the first one type in these commands:
tell application "System Events"
tell security preferences
set require password to wake to true
end tell
end tell
activate application "ScreenSaverEngine"
Now save this script as MacLock or something to indicate that this is the one that needs to be activated when your phone is no longer in connectivity range. (Make sure you know where you save it, because you will need it.) After saving the file, create a new script and input these commands:
tell application "System Events"
tell security preferences
set require password to wake to false
end tell
end tell
tell application "ScreenSaverEngine" to quit
Save this one as MacUnlock or something to indicate that it's the script which needs to be applied when your device is back in connectivity range. In case you want to, you can copy paste my text directly into AppleScript so that you don't have to type them yourself. Now go back to the Proximity Preferences window and select the MacLock file as the Out of Range Script and the MacUnlock file for the In Range Script. Once this is done, your Mac will automatically lock itself whenever your phone is no longer in Bluetooth range.
From what I've noticed, some users have had a few issues with the unlocking script. The screensaver would disappear, but the screen would stay black. If this happens, just type in your password and everything should go back to normal. To avoid these problems in the future, open the MacUnlock script (or whatever name you gave to the one that activates when your device is in connection range) and add this to the existing commands:
tell application "System Events" to keystroke return
delay 1
tell application "System Events" to keystroke "WriteYourPassword"
delay 1
tell application "System Events" to keystroke return
Replace the WriteYourPassword with the actual password that you use to unlock your Mac. Now save the script under the same name as before and everything should be up and running.