I use a macmini for music in my house and usually use the Remote.app to control it on either my iPhone or iPad. The problem is I’m often sat at my PC and think using a browser would be easier. I did have a little look for an app that I could install under nix but nothing turned up so I wrote my own.

Before you start please bear in mind that this app is totally vulnerable and it was never intended to be secure, quick and dirty is the way I like it!

First of all enable the webserver in OS X (this was tested on OS X ):

Then you’ll need to change the config to enable php5, change the user apache runs as and then change the start page.

1
sudo nano /private/etc/apache2/httpd.conf

Uncomment the php5 line:

1
LoadModule php5_module        libexec/apache2/libphp5.so

Change the user to replicate your shortname:

1
2
User phillips321
Group staff

And finally change the Directory index to point at index.php

1
2
3
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

Now restart the apache service

1
sudo apachectl restart

Now copy the following code into a file named index.php under /Library/WebServer/Documents and your good to go (code here if copy paste doesn’t work)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?
$command = $_GET['command'];
switch ($command)
        {
        case "playpause":exec("osascript -e 'tell app "iTunes" to playpause'");break;
        case "next":exec("osascript -e 'tell app "iTunes" to next track'");break;
        case "prev":exec("osascript -e 'tell app "iTunes" to previous track'");breal;
        case "louder":exec("osascript -e 'tell app "iTunes" to set sound volume to sound volume + 10'");break;
        case "quieter":exec("osascript -e 'tell app "iTunes" to set sound volume to sound volume - 10'");break;
        case "mute":exec("osascript -e 'tell app "iTunes" to set mute to true'");break;
        case "unmute":exec("osascript -e 'tell app "iTunes" to set mute to false'");break;
        }
$status = exec("osascript -e 'tell application "iTunes" to player state as string'");
$vol = exec("osascript -e 'tell app "iTunes" to sound volume as integer'");
$track = exec("osascript -e 'tell app "iTunes" to name of current track as string'");
$artist = exec("osascript -e 'tell app "iTunes" to artist of current track as string'");
$album = exec("osascript -e 'tell app "iTunes" to album of current track as string'");
?>
<html>
<head><title>iTunes Remote - <? echo $status; ?></title>
<? if ($command != ""){ echo '<meta http-equiv="refresh" content="3;url=/"></head>'; } ?>
<body>
<center>
<form method="link">
        <input type="submit" name="command" value="playpause"><br>
        <input type="submit" name="command" value="prev">
        <input type="submit" name="command" value="next"><br>
        <? echo $artist; ?> - <? echo $track; ?> - <? echo $album; ?><br>
        <input type="submit" name="command" value="quieter"><? echo $vol ; ?>
        <input type="submit" name="command" value="louder"><br>
        <input type="submit" name="command" value="mute">
        <input type="submit" name="command" value="unmute">
</form>
</center>
</body>
</html>

If you’re extra special you can even add a favicon to the page.

Leave a Reply