OS X’s Mail program includes Rules (in Mail -> Preferences -> Rules) that can help you manage your inbound e-mail. You can filter messages based on content, sender, subject, and so forth, and then automatically route the messages to another mailbox. I use the rules a fair bit, particularly to route mailing list messages into mailboxes I’ve created for those lists. But there’s one other feature of Mail’s Rules that adds a lot of power—the ability to run an AppleScript on a filtered message. You can put this ability to use, even if your AppleScript skills (like mine) aren’t the greatest.
Here’s one example. Say you’ve left home for a business trip, and realize halfway to the airport that you’ve forgotten to put your Mac to sleep. All your normal applications are running, including Mail. Being the secure sort, you haven’t left any remote access methods active—Remote Login, FTP, and the like are all disabled. But you’d really rather not leave your Dual G5 sucking down the electric juice for a week. Short of calling a buddy and having them break into your home, what options do you have? Well, if you read this tip, you’ll have at least one solution at hand: you’ll send yourself an e-mail that will put the machine to sleep.
The first thing to do is create an AppleScript, so launch Script Editor (in /Applications -> Utilities). Don’t worry, this is a very simple AppleScript. It consists of exactly three lines:
tell application "Finder"
Told you it was simple. When you’ve pasted that in, choose File -> Save to bring up the Save dialog. Name your script and save it somewhere where you can find it later—I use a folder named
to store such things. Don’t worry about changing any of the other settings in the Save dialog; leave them as they are.
Now open Mail’s Preferences and click on the Rules icon in the toolbar. When the Rules panel appears, click Add Rule. In the new window that appears, give your rule a name (
Sleep my 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, and so forth that you like. As an example, here’s how I set mine up:
Note that if you’re going to use more than one condition, make sure the first pop-up is set to “All” instead of “Any.” And before you all go crazy trying to spoof your mail programs to send me a message to sleep my Mac, notice that the domain information is fictitious, and I’ve changed the rule since I took that screenshot—so spend your energy on something productive, like guessing what products Apple will roll out at Macworld Expo next week.
At the bottom of the above window, you can see the key to making this work—the “Perform the following actions” section has been set to Run AppleScript, and I used the Choose button to point to the script I saved earlier. At this point, click OK and you’re done. The next time you forget to put your Mac to sleep before leaving on a trip, just send yourself an e-mail that matches the conditions you created, and your Mac will go to sleep.
Is this a security issue? Well, if someone figured out your rule, they could send an e-mail that would sleep your Mac. Of course, figuring out your rule would probably mean they had physical access to your machine, since I’m not aware of any security holes that reveal Mail’s rules to the internet—and if they have physical access, they can do many worse things than send you a sleeper e-mail!
You can do other things in this manner as well, obviously—any AppleScript you write or find on the net could be used, although if they require interaction, there’s not much point to running them via a Mail rule. You can also use simple scripts to launch applications:
tell application "Finder"
launch application "iChat"
You might use this technique if you’re on the road and forget that you meant to launch iChat before you left—perhaps to spy on your cat using your machine’s iSight camera. Of course, to make that work, you’ll also need
Chax, which lets you set up the machine to automatically accept video chat invitations. I leave further uses of this technique up to your imagination.