Play PC games on your Mac? TUAW tests CrossOver.

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.

Related Headlines

Reader Comments (Page 1 of 3)

Add your comments

Please keep your comments relevant to this blog entry. Email addresses are never displayed, but they are required to confirm your comments.

When you enter your name and email address, you'll be sent a link to confirm your comment, and a password. To leave another comment, just use that password.

To create a live link, simply type the URL (including http://) or email address and we will make it a live link for you. You can put up to 3 URLs in your comments. Line breaks and paragraphs are automatically converted — no need to use <p> or <br> tags.

New Users

Current Users

TUAW Features

Mac 101 iPhone Around the Worldask-tuaw
Mac News
Macworld (497)
.Mac (38)
Accessories (624)
Airport (75)
Analysis / Opinion (1289)
Apple (1607)
Apple Corporate (546)
Apple Financial (185)
Apple History (38)
Apple Professional (49)
Apple TV (160)
Audio (441)
Bad Apple (119)
Beta Beat (146)
Blogging (87)
Bluetooth (15)
Bugs/Recalls (56)
Cult of Mac (868)
Deals (199)
Desktops (114)
Developer (204)
Education (93)
eMac (10)
Enterprise (126)
Features (372)
Freeware (362)
Gaming (344)
Graphic Design (15)
Hardware (1269)
Holidays (41)
Humor (585)
iBook (65)
iLife (237)
iMac (183)
Internet (304)
Internet Tools (1287)
iPhone (1340)
iPod Family (2017)
iTS (958)
iTunes (791)
iWork (18)
Leopard (355)
Mac mini (109)
Mac Pro (50)
MacBook (196)
MacBook Air (76)
Macbook Pro (215)
Multimedia (430)
Odds and ends (1414)
Open Source (270)
OS (889)
Peripherals (190)
Podcasting (181)
Podcasts (83)
Portables (196)
PowerBook (137)
PowerMac G5 (50)
Retail (571)
Retro Mac (47)
Rig of the Week (42)
Rumors (608)
Software (4205)
Software Update (393)
Steve Jobs (252)
Stocking Stuffers (55)
Surveys and Polls (96)
Switchers (111)
The Woz (34)
TUAW Business (227)
Universal Binary (281)
UNIX / BSD (61)
Video (908)
Weekend Review (74)
WIN Business (49)
Wireless (80)
XServe (35)
Mac Events
One More Thing (27)
Liveblog (0)
Other Events (231)
WWDC (180)
Mac Learning
Ask TUAW (96)
Blogs (85)
Books (23)
Books and Blogs (63)
Cool tools (443)
Hacks (462)
How-tos (480)
Interviews (33)
Mods (184)
Productivity (582)
Reviews (99)
Security (145)
Terminal Tips (56)
Tips and tricks (558)
Troubleshooting (160)
TUAW Features
iPhone 101 (23)
TUAW Labs (3)
Blast From the Past (17)
TUAW Tips (141)
Flickr Find (32)
Found Footage (70)
Mac 101 (80)
TUAW Interview (30)
Widget Watch (196)
The Daily Best (2)
TUAW Faceoff (4)

RESOURCES

RSS NEWSFEEDS

Powered by Blogsmith

Sponsored Links

The Unofficial Apple Weblog (TUAW) bloggers (30 days)

#BloggerPostsCmts
1Cory Bohon446
2Dave Caolo430
3Mat Lu324
4Michael Rose2919
5Erica Sadun280
6Scott McNulty281
7Brett Terpstra240
8Mike Schramm204
9Robert Palmer1019
10Steven Sande97
11Christina Warren617
12Joshua Ellis64
13Chris Ullrich31
14Nik Fletcher21
15Jason Clarke11
16Lisa Hoover11
17Victor Agreda, Jr.13

Featured Galleries

Macworld 2008 Keynote
Macworld 2008 Build-up
Macworld Expo 2007 show floor
The Macworld Faithful in Line
iPhone First Look
iPhone 2.0 - .Mac push e-mail
iMac 1998
TUAW Faceoff: Screenshot apps on the firing line
Boston Apple Store (Boylston Street)

 

    Most Commented On (7 days)

    Recent Comments

    More Apple Analysis

    More from AOL Money and Finance

    Weblogs, Inc. Network

    Other Weblogs Inc. Network blogs you might be interested in: