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:
- Add a description (this is for your information)
- Select "All" from the "if" drop-down box
- Under "If all of the following conditions are met:", add these things: (you will need to click the "+" to add the second item)
- "Subject" ... "Contains" ... "System"
- "Message Content" ... "Contains" ... "shutdown"
- Under the "Perform following actions:", add these things: (you will need to click the "+" to add the second item)
- "Set Color" ... "of text" ... "Red"
- "Run AppleScript" ...
- 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"

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.
Share
Source: http://tuaw.com/tag/AppleScript
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
If Safari opened it ask to quit Safari before shutingdown
So, how to fix it?
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 Permalink rate up rate down ReplyI 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 Permalink rate up rate down Reply"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^)
All I'm missing is a mail to start up your Mac...
(Kidding.)
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 Permalink rate up rate down ReplyVery cool!
Now, can you tell us an Applescript that can change the signature in a new email? (Or an email that's a reply?)
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 Permalink rate up rate down ReplyWow. I've always wanted a Mac. Now I can pwn yours.
On behalf of all spammers, I thank you.
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.
Hot Apps on TUAW
Deals of the Day
more deals- Ventev UltraTHIN Hard Shell Case for iPhone 4 for $2 + $2 s&h, more
- Body Glove Matrix Case for iPhone 4 / 4S for $3 + $2 s&h
- Pogoplug Premium Personal Cloud for PC and Mac for $10 + free shipping
- olloclip 3-in-1 Lens System for iPhone 4 / 4S for $70 + free shipping
- Open-Box Nike Aero Neckband Headphones for $13 + $6 s&h
- Adobe CS5.5 Design Premium Student for PC or Mac downloads for $337



46 Comments