Pages

Thursday, March 21, 2013

How can I repeat an AppleScript function if a variable is changed?

I am creating a script that will append the first 10 integers of an album name to a website URL for a band - part that I have working so far looks like this:

 

 

    tell application "iTunes"

        if player state is playing then

            set albumName to (get album of current track)

            set myText to text 1 thru 10 of albumName

        end if

    end tell

   

    temptext = myText

   

end if

open location "http://bandsite.com/shows/" & myText

 

So if an album is named "1999-01-04 - Great Hits" - this will return "1999-01-04" and append it to the bandsite.com/shows/ URL.

 

I need the above function to repeat itself whenever the album is changed in iTunes not the track. My work in progress code for that is:

 

Set temptext = myText

if temptext is not myText then

    tell application "iTunes"

        if player state is playing then

            set albumName to (get album of current track)

            set myText to text 1 thru 10 of albumName

        end if

    end tell

   

    temptext = myText

end if

open location "http://bandsite.com/shows/" & myText

repeat while temptext = text

end repeat

 

I keep getting snytax errors. Any help would be greatly appreciated. Thank you!


View the original article here

0 comments:

Post a Comment