iTunes Web-Based Remote |
|
iTunes Web RemoteMarch 23rd, 2004 This little tutorial will show you how to create a web based remote for Apple iTunes. It's only for Mac OS X. It requires some modifications to the Apache Web Server that make it less secure, so I recommend you do this on a computer that's safely hidden behind a router, and preferably a computer that isn't using Apache for anything else. Mac OS X Upgrade Note: Upgrading from one major version of OS X to another will likely replace your apache config file with a fresh default one. So you will probably have to make these changes again to get the remote working. Basic Idea
Step By StepYou must make a few modifications to the Apache web server. The path to your Apache Configuration file is
Now, assuming you have a default (or nearly so) Apache configuration, you must make the following modifications. First, you must enable PHP within Apache. Search for the section that starts with "
In the group of items immediately following that section, uncomment the following line:
Next, you want to make apache run as the same user as YOU. Normally Apache runs as its own user. This is the part that has some potential security risks. You need to know your short name on the system. If you don't know it, go to the Accounts section of System Preferences, and choose your account. You will see your short name. Now, back to the Apache Config file. Scroll down until you see the following lines:
You want to change the first The last thing you want to do is add
And after Now you need to save your file (
HEAD tag of this file, insert the following code so that when you call this file, it will perform the function on iTunes and then return you to linking page:
Now you want to insert the following code in the body of the php document. This code takes the commands you send it and then sends AppleEvents out to iTunes through the command line. <? $q = $_GET['q']; switch ($q) { case "": echo "You need to send me a command, then I shall execute it"; break; case "play": exec("osascript -e 'tell app \"iTunes\" to play'"); echo "Playing"; break; case "pause": exec("osascript -e 'tell app \"iTunes\" to pause'"); echo "Pausing"; break; case "playpause": exec("osascript -e 'tell app \"iTunes\" to playpause'"); echo "Toggling Play"; break; case "next": exec("osascript -e 'tell app \"iTunes\" to next track'"); echo "Next Track"; break; case "prev": exec("osascript -e 'tell app \"iTunes\" to previous track'"); echo "Previous Track"; break; case "louder": exec("osascript -e 'tell app \"iTunes\" to set sound volume to sound volume + 5'"); echo "Turning Up the Volume"; break; case "quieter": exec("osascript -e 'tell app \"iTunes\" to set sound volume to sound volume - 5'"); echo "Turning Down the Volume"; break; case "mute": mutev(); echo "Muting the Volume"; break; } function mutev() { echo "start mute function"; $data = file_get_contents("/webfolder/volume.txt"); $logfile = fopen("/webfolder/volume.txt",'w'); $oldvolume = exec("osascript -e 'tell app \"iTunes\" to sound volume'"); echo "volume data:$data:"; if ($data == "x") { fwrite($logfile,$oldvolume); exec("osascript -e 'tell app \"iTunes\" to set sound volume to 0'"); } else { fwrite($logfile,"x"); exec("osascript -e 'tell app \"iTunes\" to set sound volume to $data'"); } fclose($logfile); } ?> Now, in the code you just inserted into the control.php file. You must go back and find the two lines near the end that call the file
After you get both of the pathes right, you must now create the volume.txt file, and make it writeable to all. There are many ways to do this, but if you don't know any, use these commands in the Terminal.
That last line makes the volume.txt file writeable by all. That concludes this step.
Notice the '
You can easily add your own commands as well, if you are familiar with php and AppleScript. The EndNow you should be able to use URL's to control iTunes from anywhere in your house, or if you wanted to, you could set it up so it's controlable from the internet too. You can also use the same technique to GET info on the current song too, but that's much slower to execute. Uncomment - In an Apache config (among other places), line that begin with a # symbol are comment out, when the config file is read in, those lines are ignored. To uncomment a line, you must delete that # symbol at the beginning of the line. |
|