Put a Mac to Sleep Remotely via eMail or Text Message

Feb 6, 2007 - 4 Comments

Mail app icon

How many times have you left your Mac on, and later while you’re out and about you wish you would have turned the thing off or put it to sleep? Wouldn’t it be nice to be able to put it to sleep remotely with a quick email or text message? You can, and it’s easier than you’d think. You’re just a simple AppleScript and a few Mail rules away from putting your Mac to sleep from virtually anywhere. We’ll show you how to do it, but if you’re still confused then a screencast demonstrating the technique is also available:


Note: A alternate version of this lets you use SSH or an iPhone for remote sleep of a Mac too. Use whichever method you prefer.

The easiest approach to this uses AppleScript and a Mail rule to accomplish remote sleep via an inbound email to the Mac that is awake. The method goes like this:

How to Sleep a Mac Remotely via an Email

This will use a simple AppleScript an Mail Rule to allow for remote sleep via email to the Mac running the script. Here’s how to set this up:

  1. Launch Script Editor (in /Applications -> Utilities), and create a new Apple Script
  2. The new AppleScript should be containing the following three lines:
  3. tell application "Finder"
    sleep
    end tell

  4. Save this script as SleepMac (or something similar, as long as you can identify and find it later)
  5. Launch Mail.app on the Mac (found in /Applications)
  6. Open Mail app Preferences, then click on the Rules icon in the toolbar
  7. When the Rules panel appears, click Add Rule. In the new window that appears, give your rule a name (Sleep Mac) and then create a set of conditions to insure that the rule will only act on the e-mails you want it to act on. This can be any combination of sender, recipient, subject, content, that you like. For example, setting your own email as the sender with a subject of “Sleep Now” can be effective
  8. Select your previously saved AppleScript in the “Perform actions” setting (labeled as “SleepMac” or whatever)
  9. That’s it! Now your Mac will sleep if you send an email or text message from the address you specified. Be sure to leave Mail.app running otherwise the trick won’t work properly.

You can confirm this works by sending yourself an email that fits the rules you created in Mail app. For example, if you used your own email with a subject of “Sleep Now” as the condition for executing the “Sleep Mac” applescript, send yourself an email fitting those conditions.

You can try this from an iPhone or iPad, or another Mac, right next to your Mac with the Sleep Mac rules conditions met, and then watch your Mac go to sleep instantly when it gets the email.

If you are confused, try watching this screencast from MurphyMac.com for a visual walkthrough. It follows the older approach, but you can apply the new rules to the old method.

This nifty rick is brought to us by Rob Griffiths from MacWorld, who provides an updated version of Timmothy Griffins approach. If you know of any other methods to accomplish a similar process, share them in the comments!

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: David Mendez in How to, Mac OS X, Tips & Tricks

4 Comments

» Comments RSS Feed

  1. Dan says:

    Hmmm… What if your computer is already asleep, and you send it a sleep message.

    When you get back and turn it on to retrieve your messages, your sleep message will be among them, and it’ll turn your mac off. I think it might be better if there was some kind of date/time check on when the message was sent, against the time when the computer was last switched on.

  2. Murphy says:

    Dan –
    If you look at the original Tim Margh post he built a pause into the Automator action – and a bounce – so he’s alerted that the Mac is going to sleep. He can cancel the action before it actually goes to sleep. Nice touch.

  3. […] Alternatively, you can achieve similar with Mail.app itself, have a look at the solution here, but i like mine better. […]

  4. DAN says:

    I attempted to put this script together, but when I got to the “system” the script was not there (its missing) If someone could tell me how to fix I would really appreciate it

    Thanks!

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac