Murphy Mac - Screencasts and Tutorials » Page 'Select a Playlist by Email – And More'

Select a Playlist by Email – And More


Playlist by EmailI can see the comments now. “Why not just…” But let’s be patient and save judgements until you’ve read the whole post.

Yes, I know there are tons of ways to control iTunes from your iPhone or your touch or another computer or your fancy remote. (Murphy even dug up an old Pocket PC recently to try out Salling Clicker, which also supports BT phones) But there’s no harm in having yet another avenue for getting some music playing.

Murphy stumbled into a script that checks the content of an email for instructions on what to play in iTunes, like a playlist or an artist. But there’s more – just like the title of this post says. The script can also tell iTunes to play through external speakers via your Airport Express. That might not sound like much, but it is, because iTunes doesn’t provide the necessary hooks to control speaker selection.

The script looks in your inbox for the first email with a certain subject, like iTunes or playme. Then it looks in the body for either an artist name or the word playlist on the first line. On the next line you specify the track number or playlist name, accordingly. Optionally, on the third line you can toggle your Airport Express by entering the word remote. Nice work doctorlambo.

The Airport Express is actually the most interesting part of this script. Speaker selection can’t be scripted directly, iTunes and Applescript don’t support it. But a little addition to Applescript called Extra Suites lets you control the interface through the seldom seen Remote Speakers window, pictured above. Extra Suites can move the mouse pointer to an x-y coordinate and click. The tiny Remote Speakers window can be used as a known starting point and the script then moves to a known offset, the location of the speakers checkbox. The part of the script that checks or unchecks the box is pictured here.

Playlist by Email

It sounds rickety, but in practice it’s working well for Murphy. If you always play to external speakers or always have the same set of speakers selected you don’t need this part of the script. You could also create multiple scripts and use different keywords in the subject to kick them off, if you have multiple speaker on/off needs.

Extra Suites is a little application you need to have running if you’re using that part of the script. You can put it in your applications folder or wherever you’d prefer to keep it. Add it to your login items to make sure it’s always running.

Murphy’s most popular post of all time, Sleep Your Mac By Email, explains how to configure Mail to run an Applescript when an email meeting a certain criteria lands in your inbox. Refer to that post for details. Credit to Or you can schedule the script to run some other way. You’ll probably want it to run every minute or two. If you have Mail rules kicking of the script you can remove the check for new mail line from the beginning of the script.

Some debate has been spawned about how it might be insecure to kick off scripts based on arriving email. There are a few reasons why this is not a notable security risk. The email coming in looks just like any other email. An attacker has no way of knowing the email kicks off a script. You don’t have to use the word iTunes as the trigger, if that makes you feel any better. When Murphy posted about sleeping your mac he used sleeper as the trigger. Several people sent emails with this subject. Nice try.

The truth is that this method is more secure in some ways for remote control, people aren’t looking for it. When you access your Mac across the Internet using VNC the port gives you away. Port 5900 tells anyone who’s watching that you’re using VNC, and they can easily go after your password. An email is less likely to be noticed. You should probably come up with a trigger other than iTunes though. Murphy is widely read.

A slightly different approach: You might want to send a simpler email or text than what’s described above. You could make a rule in Mail that runs a script with a hard-coded playlist. Then your email would only need the trigger word, nothing else. See this post for an example of a simple script.


Extra Suites displays a reminder until you cough up $10.

You can also toggle the Computer speaker checkbox by changing the 57 pictured in the script above to 37. That’s the Y-coordinate.

Download script text. (you’ll need to open it in Script Editor and save as an applescript before use)

More information on the script can be found here.

Murphy doesn’t use VNC across the Internet. See this post about logmein.

Other tricks with Mail: Retrieve a File by EmailMail a File Dropped in a Finder Folder Fetch Messages from your Phone

Download Script | Permalink

2 comments to “Select a Playlist by Email – And More”

  1. Thanks, Murphy, for this article. This whole «control your Mac by eMail»-subject is quite interesting. I recently wrote a small article describing, how this cool technique can also be easily used to share (DRM-protected) iTunes songs among family members:

    And the eMail control is not only limited to AppleScript commands, as you can also execute Python/Perl/Ruby/C++ scripts utilizing AppleScript’s «do shell script»-command.

  2. You can also control remote speakers using UI scripting:

    tell application “System Events”
    tell process “iTunes”
    — Switch to the speakers in my bedroom
    set frontmost to true
    click button 15 of window 1 — Remote Speakers Menu
    key code 115 — Home Key
    key code 125 — Down Arrow
    key code 125 — Down Arrow
    key code 36 — Return Key
    end tell
    end tell

    Before that code will work you’ll need to enable UI scripting in the Universal Access section of System Preferences. Tested with iTunes 8.2.1.

    I figured out that the remote speakers button was button 15 by doing this:

    tell application “System Events”
    tell process “iTunes”
    set frontmost to true
    get buttons of window 1
    end tell
    end tell

Leave a comment