Let me preface this by saying this was not my idea. I originally heard of such a concept during an episode of Mac Power Users with David Sparks and Katie Floyd. I had recently fell in love with Hazel and like any good utility, it sparked my imagination and creativity for potential uses. After finishing the episode Geeking Out With Hazel, I did some quick Googling to see if I could find any documentation on the security script that David made brief mention of, unfortunately I could not. I thought to myself, how hard could it be to write my own. Long story short, it was actually quite simple and it seems like I keep thinking of features to add but for now it takes an iSight picture, logs the IP address, uploads the Safari history and last session, takes a screenshot, disables automatic login, and locks the screen. Phewww, that is a mouthful.
I started by making a folder inside of my Dropbox. For this article, we will call it Security, but really anything will do. I then created a file inside the folder that Hazel will soon be configured to watch. I originally created a (dot) file so that it would stay hidden from the default Finder view but I found the results of Hazel being triggered by a (dot) file to be inconsistent at best so it is just a simple file. I named it add_exclamation_for_recovery so that a year from now, when my Mac is jacked I won’t forget how to actually trigger this security script.
Next you will need to download a little terminal utility called iSightCapture. Just place this in an executable directory. I copied it to my /USR/BIN directory.
Ok, back to the Hazel scripting goodness. So far I have a folder in my Dropbox called Security, and a file inside of that folder called add_exclamation_for_recovery. Now its time to start creating the Hazel rule.
First, open Hazel and add your ‘Security’ folder to the left column. Click the plus sign at the bottom of the right column to create a new rule. Give it a name, like ‘Initialize Security’.
The condition that will trigger this sequence to run is as follows:
So basically, if my laptop gets stolen, I simply grab my iOS device or the closest Internet accessible computer and rename the file being watched to include an “!” and the script is executed. Simple right?
Ok, now we must define some actions to take when the script is ran. For the first action, choose “Run shell script”, leave it as an “embedded script” and copy this code in to the embedded script text box but be sure to change the directory paths to match your own folder structure
As you can guess, the first command will take a snapshot of someone using your laptop, and uploads it to your Dropbox. The next line of this script will log the current external IP address of the perp which will help you narrow down the location of your property. The final two commands will copy the Safari history and the last Internet session details to your Dropbox which might help identify who ever has your laptop if they have been surfing the web. The next action this Hazel rule will take is an automator workflow which mutes the computer, snaps a screenshot, and then restores the volume. Download it here: Automator Screenshot Workflow or create your own. Save it somewhere accessible, such as your ~/Library/Scripts/ folder, and point the Hazel action to that workflow.
Finally, since I have my laptop set to automatically login (I know it is not secure but I am lazy!) I need to the change that setting. If this applies to you then create another embedded Shell script and copy this in to the text box:
This will disable the automatic login feature and then lock the screen preventing any further use of the computer. The reason I chose to lock instead of shutdown or reboot is because it will give Dropbox more time to upload the newly created files.
There are many other actions one could add including adding a loop so that the screenshots and pictures are repeated. You could have hazel rename screenshots and pictures so that they aren’t over written when new ones are added. Frankly I am excited to see what you guys come up with to make this Hazel script even better. Please leave a comment and let me know how you are using it.