Pages

Friday, March 22, 2013

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

In AppleScript, using the equal sign in a statement such as temptext = myText tests for equality - it does not assign a value.  The set command is used to assign a value to a variable.

 

Using a repeat statement to check for an album change is also not really the way to go, since it tends to max out your CPU usage - if you create a stay-open application, it will run in the background and the idle handler will be called periodically (the default is every 30 seconds):

 

property oldText : missing value

 

on idle -- check periodically

  checkAlbum()

  return 30 -- or however many seconds before the next time

end idle

on checkAlbum() -- check if the current album name has changed

  tell application "iTunes"

    if player state is not playing then return

    set albumName to (get album of current track)

  end tell

  set myText to text 1 thru 10 of albumName

  if myText is not oldText then

    set oldText to myText -- update

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

  end if

end checkAlbum



View the original article here

0 comments:

Post a Comment