Secure your Mac with Hazel

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.

  • Pingback: MPU 047: Dropbox Awesomeness « Mac Power Users

  • http://twitter.com/deverill deverill

    Hi and thanks for posting this. It’s fun to watch the concept grow from person to person. I don’t know if it is possible or how hard it is, but something I’d be curious to see is that when the security is activated, presuming it has been stolen, could the system determine location by polling available wireless networks like pre-GPS iPod Touch/iPhones did? Even just a list of neighbors could be useful if it were, say, the metropolitan library. Just geeking out on feature creep. :)

  • http://www.twitter.com/binaryghost Don Southard

    Thanks for the comment! I actually had the same thought about GPS positioning and my research led me to Skyhook. They have a Mac OS X SDK but it is not compatible with a shell script (not surprisingly). I would have to build it as a native Objective-C/Cocoa app… Not a bad idea though. Maybe when I have more free time :)

    Don.

  • Pingback: Scripting S3 Image Uploads « Tech Blog /via Dirt Don

  • Pingback: Use DropBox and Hazel to Bust the Scumbag Who Steals Your MacBook | 40Tech

  • Coolspec

     Hi
    Thank you for a great post. Tell me, now that I have Alfred should I get Hazel as well? Can I do with Alfred what I would do with Hazel? I have the Powerpack

    Thanks a mil

    Claude

  • Gavin

    Great post, I tried to download the iSightCapture file but the website says its no longer available, know where else I can get it?

  • Anonymous

    Here you go: http://cl.ly/7H2Z

    Don.

  • Gavin

    perfect thanks.

  • Sean

    If you’re short on time, take a look at Hidden software. 

    https://hiddenapp.com

  • Jbardi

    Alfred and Hazel are different in many ways, but the major one is that Hazel automates things without your interaction, while Alfred needs you to give it a command or activate a sequence of keys.  I use both of them, as they work VERY well together, but neither one can fully replace what the other does, so they are a great combo.

  • Jbardi

    I just though of a good way to explain it better… and their names I think were given for a reason… Hazel is like your maid, she knows what she has to do and when to do it, so you can leave her to her business, while Alfred is your butler… he also knows what to do, but waits at attention until you give him a command or he heres something like a doorbell, so he then knows to answer the door.