As some of you probably already know, I've been guest-hosting G4's Attack of the Show this past week. I won't get into the gory details of how I forever shamed myself during my time on the show (you'll have to come to our reader meetup for that), but one of the best things I saw all week was DittyBot, a little something something Scott Moschella (one of the show's segment producers) cooked up that lets you remotely listen to your iTunes collection using your cellphone. Ok, so maybe yesterday's live on-air demo didn't go as smoothly as it did during rehearsal, and DittyBot isn't actually digitally streaming your music collection like with Shoutcast or Orb or whatever, but it's a damn clever trick (even if the audio quality isn't so hot) that works on nearly any cellphone, and so we had no choice but to "persuade" Scott to let us republish his DiddyBot tutorial here on Engadget.
DittyBot is an Apple Automator Workflow mixed with some Applescript. I can't code Applescript all that well, so I'm certain the Applescript coders will suggest some code fixes so that it isn't so messy. Please post any suggestions, additions, or fixes in the comments. Thanks!
Laugh all you want about the name DittyBot, but it was one of the only ways of me getting a domain name for it ahead of time. I might not need it, but at least it's there. Also, what's wrong with the name DittyBot?
If you want to use DittyBot on your Mac, make sure you read through this entire article so that DittyBot works properly. And hopefully along the way, you'll learn a little more about the simplicity and power of Automator and Applescript.
What DittyBot Does:
You send a text message from your mobile phone to your POP email account. Your text message should contain the
keywords of a song title (and possibly an artist name) that you want to hear. DittyBot finds that email (he checks Mail
every 45 seconds) and copies the song name into a text file. The song name is then copied into iTunes and a playlist is
created from your search. Next, DittyBot loads Skype (the internet telephony app) and begins calling your mobile phone.
Your mobile phone rings and when you pick it up, you should hear your song start playing in all its compressed glory.
DittyBot will play your selection to you over your phone until you hang up. Mind you, this all should happen within 1
minute of sending your song request (depending on the speed of your POP server). Sometimes it's even quicker!
That wasn't so hard now, was it?
Sure, this is silly. However, it's only a small demonstration of the power of Applescript. DittyBot's ability to juggle all these apps should give the tinkerers out there yet another reason to consider buying an Apple.
Before you can start using DittyBot to play iTunes songs through your cell phone, there's a decent amount of setup involved. So pay attention.
Setting Up DittyBot:
For those of you without a traditional POP email account, here's instructions for setting up Gmail for POP access.
Yahoo offers a pay-for POP account, as does Hotmail. Mail.app must be configured to work with your POP (or IMAP)
account. Note, this is not your cell phone's email address that we're talking about. You must have an email account set
up to receive email sent from your cell phone.
Here's my mail setup. I have digitally removed my password from the dialog box for security purposes, but you'll have to put yours in there.
You're going to need a couple more things:
- A Skype account with SkypeOut so your computer can call actual telephones. This costs money, but not much. I spent $12 US for about 600 minutes. Skype now accepts PayPal, which makes the process super-easy. There's never been a better (or geekier) reason to have a SkypeOut account.
- You also need OS X running Tiger. Sorry, but right now Applescript and Automator are the only way I could think of for making this work. Consider this a challenge to the Windows and Linux community. I know it's possible to do under Windows (and Linux for that matter), but I also know it's not this easy. Prove me wrong!
Okay, you've got all that. Now what?
Well, you need to:
- Download and install Soundflower. It's a free application that reroutes your system's audio and ultimately tricks Skype into thinking that your Mac's audio output is a microphone input. Essentially, Skype thinks the audio coming from iTunes is coming from a non-existent microphone.
- It should also be apparent that you'll need the latest version of Skype for OS X Tiger. I scripted DittyBot to
work with the official release of Skype (126.96.36.199), not the beta. So I recommend that you avoid using the beta
version of Skype.
After you install Soundflower, open System Preferences and then open the Sound pane. Make your Sound pane's Input
and Output tabs look like the image on the left. Soundflower is not a stand-alone app. Instead it installs as a System
Preferences element and runs all the time. You can always change your inputs and outputs back to normal. Once you
change the Sound pane to match the image, you will no longer hear any sound coming from your computer. Note that this
will be true only when the input and output in the Sound pane are both Soundflower. However, this sound setup is
necessary in order for Skype to pipe iTunes through to your phone.
Keep the System Preferences window open and click Show All and in the System category. Then, click Universal Access. At the bottom of the Universal Access window, enable the check box next to Enable access for assistive devices. This must be enabled so that Applescript has the ability to press buttons inside of Skype.
You'll also need to download the DittyBot dmg file (300K) that contains the DittyBot workflow, DittyBot Activator, and the readme.txt. Move or copy DittyBot.workflow to the root directory on your Hard Drive. Root is your top level folder and contains all the other folders on your hard drive. Simply double-click the hard drive icon on your desktop and copy or move DittyBot.workflow there. I couldn't figure out a better place to put it and the way DittyBot is written, the workflow file must be in your root folder.
The Applescript program called DittyBot Activator can be run from anywhere on your computer. When DittyBot is activated, he creates a text file in your root directory called requested_song.txt. You can change the location of this text file by editing Action #5 in DittyBot.workflow.
You're not done yet. You need to add an empty playlist to iTunes and call it DittyBot. And finally, you need to edit one of the Automator actions and the Applescript inside the DittyBot.workflow. This is much easier than it sounds. Just run Automator (located in your Applications folder) and open the DittyBot workflow. We'll go through the items you need to change step-by-step.
Action #3 is Find Messages in Mail. Put your mobile phone's email address in the blank box next to the line that says Sender Contains. This way, DittyBot knows how to find text messages (song requests) that you send from your mobile phone.
Action #7 is Run Applescript. This is the heart of DittyBot. There's a few things here you need to edit.
Look for the line that says delete (every message in inbox whose sender is and add your mobile phone's email address in between the quotes. Make sure you don't delete the quotation marks.
On the line that says delete (every message in trash mailbox whose sender is and add your mobile phone's email address in between the quotes. Again, don't delete the quotes.
In the Skype section, look for the line that starts with set value of text field 1 of window 1 to and add your cell phone number (with area code) after the plus sign. I would also recommend starting the phone number with 1. So, my fake number would be +12125551212.
By now, you know that DittyBot finds your song requests by reading your emails. However, he needs to know which line of your email contains your song request. This will normally be line ten. If however your mail is different (I could only test this with my cell phone), you need to count how many lines down your song request is. If you need to change this number, edit the lines that say set song_letters to the count of the characters of (paragraph 10 of the front document) AND set songName to characters 1 through (song_letters - 1) of (paragraph 10 of the front document) as text. Change the 10s to whatever line number your song request falls on inside song_request.txt. Take a look at the second image below for clarification.
The curious-types out there are probably wondering what we just did. Briefly, we added your email address in Action #3 so that DittyBot knows to only look for email coming from your cell phone. We again added your phone's email address to Action #7 so that DittyBot removes the email from your Inbox and permanently deletes it. The first line sends it to the trash, the second deletes it from the trash. A WORD OF CAUTION: If you regularly send notes from your cell phone to your computer via text messaging, DittyBot will delete them! He's smart enough to know not to delete any old emails from your cell phone or emails from other people, but ones you send from your phone to your computer on the days DittyBot is running will be permanently deleted. This isn't a problem with song requests however, we want those to be deleted after DittyBot reads them.
We also added your mobile phone number to the Skype section of Action #7 so that Skype knows which number to call back with the requested song.
That's all there is to it. Just save the DittyBot workflow and make sure it's in your root directory. To run DittyBot, all you have to do is run the Activate DittyBot application. You'll see the workflow running up in your menu bar with a red stop sign next to it. You can stop the workflow by pressing that red stop sign. However, to stop DittyBot entirely, you'll have to give the three finger salute. This means, you can only quit DittyBot by pressing Command+Option+ESC (this is equivalent to Windows' Ctrl+Alt+Delete). Select DittyBot Activator and press Force Quit. I did say that I wasn't very good at Applescripting, didn't I?
Requesting a Song:
To send a song request you'll have to compose a text message from your cell phone and make the recipient an email
address instead of a cell phone number. I send song request text messages from my cell phone to my plasticbugs.com
email address. Almost any phone with text messaging capabilities can do this. Just keep an eye on how many requests you
send. I can only send 100 text messages a month before incurring overage fees, But DittyBot is so darn entertaining
that in one day I sent him 15 requests. Trust me, it's easy to do.
When requesting a song, you should only include as many keywords as you need. Because DittyBot uses iTunes' search to find song matches, you do not need complete song names and capitalization does not matter. For example, if I want to hear Ring of Fire by Johnny Cash, I send a text message to my email account that says ring fire cash. That way, it will only play Johnny Cash's version of Ring of Fire and not Social Distortion's cover of Ring of Fire. I include just enough keywords to get me one or two matches.
If more than one song matches your search terms, your playlist will contain all of those songs and iTunes will play them in the order that they were added. However, if you have every Beatles album and just send a text message that says beatles, iTunes will try to add every matching song to the DittyBot playlist. This will cause the script to take too long and ultimately iTunes will not play the playlist at all. You'll still get a phone call, but you will only hear silence. I've found that the most songs that I could match before DittyBot crapped out was around eight. You can make this number higher by changing the delay times inside Action #7, but this will ultimately cause DittyBot to call you back that much later.
Just think of the contents of your text message as what will be typed into iTunes' search window.
Good searches: buffett margar will get you Margaritaville by Jimmy Buffett - clash rudie calling will get you Rudie Can't Fail by The Clash on the album London Calling Bad searches: any request that will match more than eight songs
When DittyBot is running, he will check for emails from your phone every 45 seconds. If he doesn't find one, he will still execute other portions of the script. However, he will not call you and he will not play any songs. Instead, you'll briefly receive an Applescript error that you can ignore (further evidence that my Applescript skills need help). The error message will go away after a couple of seconds. In a few more seconds, DittyBot will check your email again and the cycle will repeat.
It's best to test DittyBot when you're in front of the computer so you can diagnose any problems before you let him run while you're out.
To uninstall DittyBot, just delete the DittyBot workflow, DittyBot Activator, & the requested songs.txt file.