Skip to Content

Free TUAW iPhone app -- try it now!
AOL Tech

Filed under: Features, How-tos

AppleScript: Control your Mac with an e-mail

Have you ever been away from your Mac and wanted to shut down, restart, or needed to open an application remotely, but didn't have access to anything except your iPhone? Well, I am going to show you how to do these tasks with AppleScript and Mail.

This process is fairly easy and involves creating a simple AppleScript and some Mail rules. Note that since these rules will cause your Mac to perform the listed action when they run, be careful when testing!

Continue reading to learn how to build this AppleScript.
Creating the AppleScripts

For this how-to, I am going to show you how to shutdown, restart, and sleep your Mac. Just copy the following scripts into the Script Editor.app (~/Applications/AppleScript/Script Editor.app). These scripts are the Finder scripts that I showed you earlier.

Shutdown
tell application "Finder"
shut down
end tell

Restart
tell application "Finder" to restart

Sleep
tell application "Finder"
sleep
end tell

Saving your AppleScript

Click File > Save and choose "Script" from the "File Format:" drop-down box. Remember where you save the .scpt file.



Setting the Mail rules

This part is fairly simple and settings may vary by user preference. Open Mail.app and navigate your way to Preferences > Rules and click "Add Rule," then follow these instructions for each command you want to use:
  1. Add a description (this is for your information)
  2. Select "All" from the "if" drop-down box
  3. Under "If all of the following conditions are met:", add these things: (you will need to click the "+" to add the second item)
    1. "Subject" ... "Contains" ... "System"
    2. "Message Content" ... "Contains" ... "shutdown"
  4. Under the "Perform following actions:", add these things: (you will need to click the "+" to add the second item)
    1. "Set Color" ... "of text" ... "Red"
    2. "Run AppleScript" ...
  5. Beside the "Run AppleScript" action, you will see a choose box, click it and navigate to where your saved script is located. Click on the script and then on "Choose File"
You should end up with something like this:


Running the script remotely

To run the script, all you have to do is send an e-mail to your account with the subject and message contents as you specified them in creating the rules. For the rule that I created, I would send a message with "System" as the subject and "shutdown" as the contents of the message.

Additional Notes
  • 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)
  • If you have multiple rules in Mail.app, you might want to consider using "Stop Evaluating Mail Rules" as an additional action
  • It is also a good idea to have Mail.app check for new messages often for this to work well

Next week, I will show you how to apply this to iTunes in order to control your party shuffle.
jobs & resumes
Lead Blogger

AOL Find a Job - New York, NY (4 weeks ago)

See More Relevant Jobs ›

Reader Comments (Page 1 of 3)

Tip of the Day

Use Spotlight as a reference tool. Type any word in the Spotlight box and one of the top entries will be a definition. Click on it, and it will bring up the dictionary application to check the word in either the dictionary, thesaurus, Apple database, or Wikipedia.


Follow us on Twitter!
 TUAW [Cafepress]

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Google Earth for iPhone
Podcaster
Storyist 2.0
AT&T Navigator Road Test
Bento for iPhone 1.0
Scrabble for iPhone
Tom Bihn Checkpoint Flyer Briefcase
Apple Vanity Plates
Apple booth Macworld 07
WorldVoice Radio
Quickoffice for iPhone 1.1.1
Daylite 3.9 Review
DiscPainter
Mariner Calc for iPhone
2009CupertinoBus
Crash Bandicoot Nitro Kart 3D
MLB.com At Bat 2009
Macworld Expo 2007 show floor

 

More Apple Analysis

AOL Radio TUAW on Stitcher