2

I want to execute a script when iTunes plays a new song. I have looked at Automator as well as the iTunes Library in Script Editor, but don't see anything that will allow me to do this. Any ideas?

4

You could use an AppleScript to watch for song changes. The script below will get you started:

tell application "System Events"

    set previousSong to ""

    repeat
        if exists process "iTunes" then
            tell application "iTunes"
                if player state is playing then
                    set currentSong to name of current track
                    if currentSong is not previousSong then
                        set previousSong to currentSong

                        -- Execute your script, command, or application here                        
                        say "Song changed"

                    end if

                end if
            end tell

            -- Wait some seconds
            delay 10
        else
            exit repeat
        end if
    end repeat

end tell

This AppleScript checks every 10 seconds for the name of the currently playing song. If the song name differs from 10 seconds ago, the phrase "Song changed" is spoken.

  • This is would probably the best way, however if you do not intend to skip songs, may I suggest, that you wait for the length of some, so it doesn't run so often. Just drag iTunes to Script Editor to see how to get that. – user14492 Nov 15 '15 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .