Anti-theft protection with Automator

So, you want to protect your precious mac from thieves. Well, you’ve come to the right place. Sort of.
This is more of a “try-to-catch-or-at-least-get-a-glimpse-of-the-bastard-who-did-it” kind of solution than a real anti-theft one.

THE BACKGROUND:
I love my mac. And all of my precious work is on it. I mean I do have backups and stuff but still, having my mac stolen would suck.
So I started looking around for stuff that could protect me in some way. I did find a lot of interesting stuff, including:
- password-protect it
- tie it to the desk with a kensington cable
- sound loud alarm and flash screen and maybe the bastard will get scared and run away
- buy a subscription to a service that fakes a malfunction of the mac, then hope the thief takes it to the repair shop, then pop up a message like “this mac was stolen. contact the police or something”
None of the above struck a chord, since i wanted something simple, customizable and free.

THE IDEA:
Anyway, the ideea is to use Apple’s Automator in an application that runs on boot to do the following:
- Snap a picture of the bastard (using iSight)
- Take a screenshot of the current desktop
- Save those two files locally
- Scale files
- Send them via FTP
- Wait for 30 seconds and repeat

1. Create directories to work in

The following illustrate my choices, you should replace with whatever you like:

“/Users/Square/mac_capture” – main location
“/Users/Square/mac_capture/captures” – initial location of captured files
“/Users/Square/mac_capture/sent_captures” – local storage for captured and sent files

2. Create the Automator workflow

Open up Automator (should come with OS X), you cand find it in “Applications” – I use Leopard so setting might differ a bit if you’re using something else.
Choose “Custom Workflow”.

Updated 24th of February 2009: Added a new action on top of all the others in order to hide the application!
(found a hint on an apple forum but can’t really remember where…)
Drag the “Run Applescript” action to the workflow and type in:

on run {input, parameters}
tell application "Automator Launcher" to quit
tell application "System Events"
set visible of process "Google Helper" to false
end tell
return input
end run

This hides the annoying status bar message (and also assumes you’ve named your application “Google Updater”. That seemed like a good name to me

Run AppleScript

Drag the “Run Shell Script” action to the workflow – this uses a small utility to capture an image using iSight
Type:

Drag the Get Specified Text action in the workflow – this specifies the captured image path
Type in:

/Users/Square/mac_capture/captures/camera_capture.jpg

Get Specified Text

Drag the Rename Finder Items action in the workflow – this renames file to include date
Use these settings:

Rename Finder Items

Drag the Rename Finder Items action again in the workflow – this renames file to include time
Use these settings:

Rename Finder Items

Drag the Set Computer Volume action – this is used to mute the computer becouse the “take screenshot” action makes a sound (and that’s no good)

Set Computer Volume - to mute

Drag the Take ScreenShot action – this snaps a picture of the current screen

Take ScreenShot

Set Computer Volume – set it to half the level

Set Computer Volume - to half

Scale Images – scales the screen capture image to 60% (so it won’t take to long to upload to FTP)

Scale Images - 60%

Get Specified Text – handle to the screen capture file

Get Specified Text

Drag again two Rename Finder Items to add date and time, just like above.

Drag a ftp_transfer action and input you details.

You need FTP write access to a domain. Specify you username, password, remote path and local path,
and don’t forget to select “Put to ftp”:

ftp_transfer

Updated 24th of February 2009: I discovered pretty soon that if the Internet connection isn’t working, the remainder of the workflow will move the captured files to a new directory anyway. That was no good. The way it should work is that if it fails to connect via FPT, it should keep the files, and try to upload them the next time. So I added a little AppleScript that takes into account the fact that “ftp_trasnfer” returns “Not connected.” in case of failure:

Drag the “Run Applescript” action to the workflow and type in:

on run {input, parameters}
if (input as text) contains "Not connected." then
tell application "Google Helper" to quit
else
end if
return input
end run

That’s about it. You can test the workflow and see the results in both the local directories and the FTP location.

NOTE: You might want your workflow to take continous shots since just one image might not be enough. Just a Delay action and specify the time (say, 30 seconds) then add a Loop action and specify the duration or the times you want it to repeat.

Now save it, and then save it as application.

3. View images from FTP

Your images are now stored both on the computer and the FTP server (if there’s a working internet connection, of course). But how about viewing the images?

Use you preffered editor to create a new file, index.php in the same location as the files:

That will create a listing of images and name, plus links to the full size image.

Now YOU have a fighting chance!

ISIGHTCAPTURE

isightcapture is a program that lets you capture images with isight, from the command line.
It is created by Axel Bauer and you can download it here:

KNOWN ISSUES:

For the application to be any good, you need to make it start at boot time. That’s fairly easy. You also need it to be as invisible as possible. I can hide it from the dock but there’s a status message in the menu bar that I just can’t get rid of. Will post my findings later on.

Updated 24th of February 2009:
See the first workflow action for the means to hide the status bar message.
Also, to hide the application icon in the dock, try this:
- right-click the application in Finder
- select “Show Package Contents”
- open Contents -> Info.plist in some text editor
- change “false” to “true” under the line <key>LSUIElement</key>

This is “work in progress” and certainly far from perfect. Please leave a message if you feel you can contribute in any way.

This entry was posted
on Tuesday, December 23rd, 2008 at 18:42 and is filed under Mac.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Hi, I’m new to automator – I kept getting errors on the get specified text and rename finder item actions but found that placing a new action and deleting the old one seemed to do the trick. Wow, this is awesome thanks for your hard work. Any news on hiding the application more?

Glad to hear you got it to work!
About the “hidding the application” bit, yes, I’m happy to say I think I nailed it down. See the updates in the original post (24 Feb 2009)
(it might sometimes happen that the status message still appear for a split second. I thought that was ok though)

Thank for this great script. It works great for the most part but I’ve had a few problems:

1. the screen capture jpg worked 100% but the camera capture jpg didn’t rename (to add the date/time). Because of this, there was only one camera file instead of ongoing creation of files.

THE FIX:
After the “Run Shell Script”, use “Get Specified Finder Items” instead of “Get Specified Text” as listed above.

2. I’ve added your Feb 24 update (no internet connection) but noticed that if there’s no internet connection, it completely stops the scrip (even though I set it up on a loop). Is there a way to let it continue the loop (taking camera & screen captures) and ftp them when it re-detects net connection?

3. I’m using iAlertU. Is there a way to auto-start your script only when iAlertU (or Lockdown) is active instead of on every OS startup?

4. I found no need for muting the sound on screen capture since (at least in OS 10.5.7) the capture doesn’t make any sound.

I thought you might as well capture some internet related information (ip adress, provider node, location etc) using something like the output of a traceroute to any server, and send this info
at each boot…This could help find the place where the stolen mac is used from…Ideally it
should be a stealth process, burnt in the boot rom… Thanks to Apple for thinking to it
for the next macbooks !

I really like your approach to a good idea.
However, instead of taking photos/screenshots at a 30 second delay, I think it would be more convenient if you could activate it remotely. For example, one could change the contents of an online text file hosted at your webserver, which would then activate this program. Therefore, you would only activate the program when you know your mac has been stolen.

Thanks,
Since posting this I’ve modified things a little to suit my own needs. I’ve given up on uploading files to FTP and instead email them to myself. It seems that’s rather simple to do.
My current setup includes:
- Run AppleScript (hide the application)
- Run Shell Script (launch isightcapture)
- Get specified text (get path to captured image)
- Rename Finder Items (add date and time to file name)
- Run Shell Script (email the resulting image)
… and repeat everything for the screen capture.

Also, I thought it would be better to use OS X’s own system for recurring tasks so the part with the 30 second delay is out of the script. (I did a bit of research but never really wrote everything down, but if there’s any interest I might write a little about how to do it, although you can find that info elsewhere)

You idea is pretty nice though, I’ve only thought about doing that locally, never remotely. I think I’ll look into that when I have some time, thanks.

Wow, this works really well! Thanks for the clear and extensive walkthrough.

I had to make some changes though, and I have three questions.

1) A bit of a n00b question: when would you have this script run? I would think every time someone opens my Macbook, unless they press some secret key combination. So, that would need some extra script: “run me on start up or wake up” and “stop me when [some key combo] is pressed”. Could you perhaps help me with that?

2) How can I supress the small light next to the cam? Everytime a shot is taken, the light is on which is very much like shouting “Well hello there, I’m taking your picture!” Is there any way to turn off the light?

3) Both the screen and the cam are captured which is great! But, I can’t figure out how to attach the pictures to the mails that are sent. How do I do this?

Hope you had fun with this!
A quick reply to your questions:
1. you might want to look into cron, crontab, or the LaunchDaemons and LaunchAgents, I think they’re called now. Also check out CronniX
2. I’ve never heard of any way to suppress the green led, sorry.

As I am man enough to admit when someone else did a far better job than me, I have to point you to another product I recently discovered.
It’s called prey and basically does the same thing (cam capture, screenshot, plus some basic network info and some wi-fi stuff). What’s cool about it is that you can choose to use their control panel (I think that’s a payed option, with a nice little interface and stuff, keep screenshots there, decide when to turn it on/off, etc) OR (the route I took) use it in a sort of “manual mode”, for free, (you put or delete a file on some ftp server and, if the file is missing, it starts taking pictures).
Sure, I loved customizing everything and learning some Automator stuff (as I’m sure many of you do), but this is a cooler, simpler product…

I’ve searched and searched and found it!
I’ve never dug into the command line much but this lets you send an image attached:
for f in "$@"
do
uuencode $f camera_capture.jpg | mail -s 'Mac Capture CAM' email@domain.com
done

It loops through the files which are the result of the above action.
I used it twice (once for the camera capture and one for the screen capture, so you get 2 emails)To make this all simple, here’s the latest version of the workflow I had before I stopped using it (of course, it won’t work out of the box since it contains my system paths)Download workflow

That’s the same code as you already posted earlier in the comments I have tried that, but the images just don’t get attachted. I also tried putting the email script before the renaming actions, figuring “camera_capture.jpg” is not to be found anymore after renaming, but still no attachments..