jump to navigation

Straight from the Archatechs Geek Lab- control iTunes with your phone! (part 1) May 11, 2006

Posted by Nick in Home audio/video, VoIP.
trackback

Editors Note:  Archatechs has moved. This article is not maintained here.
phonetunes

Part 1 – the setup

This week we are going to look at a quick and dirty (and I do mean dirty) way to control Apple’s iTunes software with Asterisk server. If you’ve been a good nerd and followed the start-up guide over at Nerdvittles then you should have a nice Asterisk box up and running. If you are truly of the geek at heart you may have even followed our lead and set up at least one AirPort Express audio zone. Well, the Airport thing works great if you are with in reach of the computer driving the whole mess. But what if your computer is in 2nd floor office and you are rocking out to the new Bruce Springsteen album in your basement and you want to switch tracks to Froggy Went a Courtin’?

We guess you could walk upstairs and change songs. But honestly, we are geeks and vehemently predisposed to a hatred of physical activity, especially climbing stairs, right? Don’t worry, with our PhoneTunes script and a few other tools, you can just pick up your phone and change the track with a quick phone call!

If you feel like a dork just reading this (imagine how we felt typing it?) just hang in there. There are some practical uses to this example too. Besides presenting a good example for how you can make your phone work for you, there are some real uses. We at Archatechs like to listen to our music a ear-bleeding volumes and frequently have a frantic dash to mute the volume when an important call comes in. With our PhoneTunes script you can have asterisk pause your tunes as soon as a call comes in. Once you hang up Asterisk will resume the song and your head banging can continue. We’ve also used a modified version of this script to play a particular MP3, the sound of a phone ringing, when we are outside, via our outdoor speakers. Then again, the boys down in the Archatechs Labs burn easily…

This one is a little involved. It requires some knowledge of the Linux and Mac OS X command line. If you haven’t played with tools like SSH (for secure remote login) and BASH scripts before, you may just want to sit this one out. Remember, you can always drop us a line at info@archatechs.com if you are in the
Central Virginia area and interested in help with any of our projects.

Requirements:

Preparing the OS X Box

We prefer to create a special user account in OS X just for controlling iTunes. Since we’ll be using SSH with key-based authentication, a dedicated user can provide a little bit of protection.

  1. Download the iTunes script by Acmetech. You can get it from us or them.
  2. save it in the home directory of your user as itunes

Prepairing the Asterisk Server

terminal

The first step to create a Frankenstein-like harmony between your phone and your audio system is to set up a few things on the Asterisk side.

SSH into your Asterisk server. You’ll want to first change to the Asterisk user.

su – asterisk

Now we can create the SSH keys. SSH, using key-based authentication, will allow the Asterisk server to execute commands (programs) on your OS X- without human intervention. This can be a security hazard if not handled properly. We assume that if you are attempting this at home then you know what you need to do to secure you own set-up.

ssh-keygen –q –f ~/.ssh/id_rsa –t rsacat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keyscat ~/.ssh/id_rsa.pub | ssh USER@YourMac ' cat -\>> ~/.ssh/authorized_keys'

You will be prompted to enter a phasephrase. Leave it blank. Both times.

Make sure to replace USER with the user you wish to use on OS X and YourMac with the full DNS name or IP address of your mac.

Installing PhoneTunes

Dedicated nerds though we may be, there is one thing we are not: programmers. However, we have attempted to make this process as easy as possible (did we mention the installer script coming soon?). We’ve created a little installer script that should help you get up and running. That being said, all you experienced BASH scripters out there will no doubt find many areas for improvement. Bring it on! Seriously, drop us a line at info@archatechs.com and let us know what you’d change. (yeah, and we know a case statement would look a lot nicer, anyone want to write it?).

You can download the PhoneTools scripts here, or run the following commands from your Asterisk box (make sure you are still the asterisk user):

wget http://www.nickdawson.net/archatechs/phonetunes.tgz

tar –xpzf phonetunescd phonetuneschmod +x installphonetunes.sh

At this point you’ll need to open the phonetunes.sh file and fill in the variables at the top of the file. They should be apparent.

Finally, you can run the installer.

./installphonetunes.sh

Since this is nothing more than a text file containing a BASH script, feel free to open it first and poke around. Make sure you are comfortable with what it is going to do.

Setting up the extension:

You can do some of this in FreePBX (the web-based front-end to Asterisk@home) but we found it was just faster to edit your config files manually.

SSH into your Asterisk server. You'll want to edit the /etc/asterisk/extensions_custom.conf file. But first we need to make a backup!
Cp /etc/asterisk/extensions_custom.conf \ /etc/asterisk/extensions_custom.bak

Now we can do the editing…
nano /etc/asterisk/extensions_custom.conf

Scroll down towards the bottom. Just before the line that looks like this:
[from-internal-custom]
paste the following:
[custom-phonetunes]
exten => s,1,goto(custom-phonetunes,1,1)
exten => s,2,background(custom-phonetunes)
exten => 1,1,AGI(phonetunes.sh|1) ;play
exten => 2,1,AGI(phonetunes.sh|2) ;pause
exten => 3,1,AGI(phonetunes.sh|3) ;advance
exten => 4,1,AGI(phonetunes.sh|4) ;rewind
exten => 5,1,AGI(phonetunes.sh|5) ;status

Now, scroll down a bit more, below the [from-internal-custom] and look for include => custom-speed-dial
Just below that, paste the following line
exten => *30,1,goto(custom-phonetunes,s,1)
Of course, you can change *30 to anything, such as 488637 (for itunes).

Once that is done, save your extensions_custom.conf and reload asterisk:
asterisk -r this will bring you into the Asterisk command line
reload the reload command will load your changes into your Asterisk server

I've you've poked around in the phonetunes.sh script you've probably noticed the first argument it checks for is 9 and we are only using 1 – 5 for our controls above.
That's the subject of our bonus feature for next time.

Comments»

1. joey_g - January 25, 2007

beautiful online information center. greatest work… thanks

2. Female Pee Outdoors - August 4, 2009

nice! i’m gonna make my own journal