Latest in Applescript

Image credit:

Mac Automation: create a Mail-triggered "spy cam"

Cory Bohon

Have you ever been away from your Mac, then come back only to find that your co-worker has stolen your favorite Apple pen? Well, I am going to show you how to catch them in the act by creating a Mac "spy cam." For this how-to, you will need to create an Automator workflow, AppleScript, and some Mail rules. So, cue the James Bond music, and let's begin. You do need an iSight or a newer Mac with a built-in camera. (Yes, I know there are some tools prebuilt to do this -- but what's the fun in that?)

Continue reading to learn how to create the Mac spy cam.

Creating the Automator workflow
Let's first create the Automator workflow; this will take the picture and e-mail it to you. To create this workflow, just place the following Automator actions together (in the same order):

  • Take Video Snapshot
  • New Mail Message
  • Send Outgoing Messages

Now we need to change some of the settings for the actions. In the "Take Video Snapshot" workflow, make sure that the "Take picture automatically" checkbox is checked. Be sure to fill in the "New Mail Message" info for the To and Subject fields; also specify which account it will be sent from.

Saving the Automator workflow
Let's save the Automator workflow somewhere where you can find it later (for instance, you may want to create an "Automator" directory in your Documents directory). In Automator, click File > Save, select "Application" from the "Format" drop down box; type a file name, then click save.

Creating the AppleScript
This is going to be an extremely simple AppleScript, since will open via the Automator action and that's about all we need. Open the Script (found in ~/Applications/AppleScript/ ). Paste the following script into the editor (if you saved your Automator workflow as a different name, replace the "Take Pictures and E-mail" to the name of your saved workflow).

tell application "Take Picture and E-mail" to launch

Now save the AppleScript by clicking File > Save in the Script Editor. Type in a file name and make sure the "File Format" is set to "Script" before clicking the save button.

Creating the mail rules
To link all the parts together, let's create the Mail rules. Open's preferences (command + , ) then click Rules. Click the "Add Rule" button. Type a description and select "All" for the "If ALL of the following conditions are met."

Now let's add the conditions (you will have to click the plus sign to add more conditions):
  1. From ... Contains ...
  2. Subject ... Is Equal To ... System&*Pic
  3. Message Content ... Contains ... Picture
Add these rules under "perform the following actions" :
  1. Set Color ... of Background ... Blue
  2. Run AppleScript ...
For the run AppleScript rule, click the choose button and find your AppleScript that you just made. Then click the "Choose File" button.

Running the Script
To run the script, all you need to do is send an e-mail from the account specified with "System&*Pic" in the subject line, and "Picture" in the body of your message.

Additional Information
  1. Please note that scripts such as these may be used against you by: co-workers, roommates, friends, crazy monkeys, and people on Digg
  2. By changing the subject line condition to be a "password," you will decrease the likeliness that #1 will happen
  3. You can include unusual characters for message content conditions (i.e. #, @, or ^) in order to avoid accidentally running a script that you didn't want (for example use: #shutdown# instead of just shutdown)
  4. It is also a good idea to have check for new messages often for this to work well

From around the web

ear iconeye icontext file