Skip to Content

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.


Categories

Features How-tos

var digg_url = 'http://digg.com/apple/Control_your_Mac_with_an_e_mail'; Have you ever been away from your Mac and wanted to shut down,...
 

Add a Comment

*0 / 3000 Character Maximum

46 Comments

Filter by:
c3p0

If Safari opened it ask to quit Safari before shutingdown
So, how to fix it?

May 21 2008 at 6:31 AM Report abuse rate up rate down Reply
MagicMike

But what about open apps like Safari, when they prompt you with a few tabs open, if you wish to close?

May 20 2008 at 2:50 PM Report abuse rate up rate down Reply
Ben

I got the applescript and the rule excatly like in the article, but it doesn't work for me. I can start the script manually and it works, but I can't trigger it by email. I doublechecked the "codewords". Does anybody have a clue what's going on?

April 17 2008 at 8:11 AM Report abuse rate up rate down Reply
meatleg

"If you have multiple rules in Mail.app, you might want to consider using "Stop Evaluating Mail Rules" as an additional action"

Why? Please explain. (^o^)

April 14 2008 at 1:38 PM Report abuse rate up rate down Reply
András Puiz

All I'm missing is a mail to start up your Mac...















(Kidding.)

April 13 2008 at 11:58 AM Report abuse rate up rate down Reply
Rick Henson

I been using this to check on things at home - activates iSight, grabs picture, emails it back to my phone.

April 10 2008 at 12:52 PM Report abuse rate up rate down Reply
Eric

Very cool!

Now, can you tell us an Applescript that can change the signature in a new email? (Or an email that's a reply?)

April 10 2008 at 1:48 AM Report abuse rate up rate down Reply
graham

Why not just give Apple a $100yr and use back to my mac? Then you can control all your computers and transfer files. I do like the "security risk" any idiot that would make the rules identical to this example should be hacked.

April 09 2008 at 9:45 PM Report abuse rate up rate down Reply
Spammer

Wow. I've always wanted a Mac. Now I can pwn yours.

On behalf of all spammers, I thank you.

April 09 2008 at 1:32 PM Report abuse rate up rate down Reply
Gabe

Why bother opening you computer up to this huge a venerability - one properly formatted piece of SPAM and it's over.

Instead, jailbreak your iPhone, and install a VNC client. Then really control your mac remotely.

April 09 2008 at 12:54 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.