hvolmer
hvolmer

Reputation: 134

Applescript iTunes 11 play track n of playlist

Having trouble with something that used to work. If I run:

tell application "iTunes"
    play track 5 of playlist "xyz"
end tell 

it works fine, but if I hit next track, instead of going to track 6 of xyz it always goes to the next track in to the previous "selection" - for example the last album or playlist that was playing or another track in the same playlist that was playing before I ran this. Further, if I let track 5 play through, it player will return to the previous selection. It's as if this play command is just for one track...

If I run

tell application "iTunes"
    play playlist "xyz"
end tell

play starts at track 1 and hitting next track moves to track 2 like one might expect.

This worked fine for many years (iTunes 11 broke a few scripted things). Any idea how way it behaves so?

Upvotes: 1

Views: 691

Answers (1)

adamh
adamh

Reputation: 3292

Here's a dirty work around that uses a loop to force it manually to the track you want and resulting in the expected "next track" functionality you're after.

startPlaylist("xyz", 5)

on startPlaylist(playlist_name, track_number)
    tell application "iTunes"

        --set the view of the front browser window to playlist playlist_name -- show it, not necessary but good to know

        tell playlist playlist_name to play

        repeat (track_number - 1) times
            next track
        end repeat

    end tell
end startPlaylist

Upvotes: 1

Related Questions