Article:
  Build an iTunes Remote Control
Subject:   I wrote this, And it doesn't work.
Date:   2005-03-20 11:06:47
From:   ptwobrussell
Response to: I wrote this, And it doesn't work.

Ok. Your AppleScript appears to be good, and without trying to run it myself, your Perl script appears alright as well. If I had to guess, I might say that you haven't modified the daemon code since you neglected to mention that at all.


Realize that the code you've written is disjoint without the daemon. You serve up a page with perl...and perl just so happens to write the word "open" to a file. That's all well and good, but without having your daemon actually process the "open" command, it doesn't matter if you would have written Robinson Crusoe to the file (a great book that I highly recommend by the way).


So my advice would be to add an additional case statement to the daemon if you haven't done that (remembering to restart it afterward). Otherwise, the little AppleScript you wrote will never be called.


The crucial thing to realize here is that writing the word "open" to the file doesn't automatically call open.scpt for you.


How's that work?


M.

Full Threads Oldest First

Showing messages 1 through 4 of 4.

  • I wrote this, And it doesn't work.
    2005-03-20 11:56:22  Cool6324 [View]

    Works Great, I'm going to write one to close iTunes, now. This is so kool, I always wanted to do this too. Now, I want to have a script that Auto-Starts the deamon, from the dock, and I have done done so, but terminal just locks. So that "&" where would I put it so terminal doesn't hang.

    tell application "Terminal"
    do shell script "sudo /Library/WebServer/CGI-Executables/iTunesRemoteControlDaemon.scr" password "xxxx" with administrator privileges
    end tell


    But again terminal locks.
    • Matthew Russell photo I wrote this, And it doesn't work.
      2005-03-20 15:00:23  Matthew Russell | O'Reilly AuthorO'Reilly Blogger [View]

      Personally, I haven't ever attempted to take this approach. Have you tried putting it inside the double quotes right after "iTunesRemoteControlDaemon"? Give it a shot.

      If it doesn't work, you might want to ask if you actually reboot your system enough to merit going through the trouble of auto-starting this.

      If you want to proceed, I'd question why you're using AppleScript to simply run a shell script. You don't need this extra layer of scripting. Your shell script doesn't need to run as admin either. It just needs to run as your user account.

      The link I posted before that references login hooks on bombich.com should have been a pointer in the right direction. You ultimately want to have this thing start up as a normal daemon process just like lots of the other things that start up, right?

      If you just want a double clickable item to run the script for the dock, you can do that by researching some more on Terminal and saving a terminal session as a Term file. In fact, there a long series here on macdevcenter about that.

      M.
      • I wrote this, And it doesn't work.
        2005-03-20 15:49:46  Cool6324 [View]

        I dont re-boot my system enough, but I do have a iBook that I carry, and I sometimes have to boot. But as long as it's running, I have no problem. I also noticed, that apon excuting the script file in terminal, it does freeze which may give the appearence that nothing is happining, but don't be fooled, the script has been executed!! And do not run it again, because that will cause actions to be repeated. Once the script is opened the terminal, the only way I can get ever thing working is to run this sudo chmod 777 /private/tmp/iTunesRemoteControl in terminal. That will do the trick. I have also added some commands(change album), which anyone can do, copy and paste the info in any if the xxx.pl file's.

        #!/usr/bin/perl

        system "echo 'XXXXX' > /tmp/iTunesRemoteControl";
        system "chmod uga+rw /tmp/iTunesRemoteControl";

        print "Content-type: text/vnd.wap.wml\n\n";

        open MENU, "./menu" or die "'menu' not in current dir";
        while (<MENU>) {print "$_";}
        close MENU;


        Define a varible where XXXXX is, and add it to the daemon

        #!/bin/bash
        ##########################################################
        #Matthew Russell -25 Feb 05
        #Usage: prompt$./iTunesRemoteControlDaemon.scr &
        #
        #This simply reads a file and executes an AppleScript that
        #controls iTunes based on its content.
        #
        #kill the daemon with script killRemoteDaemon.scr
        ##########################################################

        ############
        #User Prefs
        ############
        scriptDir="/Library/WebServer/CGI-Executables"
        remoteCommand="/tmp/iTunesRemoteControl"
        delay="1.0"


        #############
        #begin script
        #############
        while [ 1 ]; do

        status=`cat $remoteCommand`

        case $status in
        "getlyrics") osascript $scriptDir/GoogleLyricSearch.scpt;;
        "nextalbum") osascript $scriptDir/PlayNextAlbum.scpt;;
        "open") osascript $scriptDir/open.scpt;;
        "RandomTrack") osascript $scriptDir/RandomTrack.scpt;;
        "Rewind") osascript $scriptDir/Rewind.scpt;;
        "FastForward") osascript $scriptDir/FastForward.scpt;;
        "MuteUnMute") osascript $scriptDir/MuteUnMute.scpt;;
        "PlayPause") osascript $scriptDir/PlayPause.scpt;;
        "VolumeDown") osascript $scriptDir/VolumeDown.scpt;;
        "VolumeUp") osascript $scriptDir/VolumeUp.scpt;;
        esac

        echo "" > $remoteCommand
        sleep $delay

        done


        As you can see I added some, pointing to the corresponding script.

        I added one to open, change album, and even get Lyrics. The same concept can be used in all applications and you can just add to the existing daemon(I'm Guessing).

        So in closing I've learned alot in two days, I think my "wapTunes" is ready to be shown off to my friends, at school.



        • Matthew Russell photo I wrote this, And it doesn't work.
          2005-03-20 16:24:11  Matthew Russell | O'Reilly AuthorO'Reilly Blogger [View]

          Glad you had fun with this. That's what it's all about!

          M.