Hello
i have a problem with this very simple script in iTunes:
tell application "iTunes"
activate
play track 1 of user playlist "myliste1"
play track 1 of user playlist "mylist2"
end tell
This script does not play the track in “myliste1” but skip directly to the track in “myliste2”
I think i see the problem : applescript ask iTunes to play track 1 in “myliste1” but itunes does not have time to play it, since applescript immediately afterwards asks him to play track 1 in “myliste2”; I need a way to ask itunes to wait until the end of the track before doing anything else.
Edit: I forgot to tell it’s iTunes 7
Hello Oliver:
I have found similar issues with iTunes, and can offer two possible solutions. The first is the one that I use currently for a similar problem:
tell application "iTunes"
set a to "The Test"
if not (exists playlist a) then make new playlist with properties {name:a}
delete every track in playlist a
duplicate track 1 of user playlist "myliste1" to playlist a
duplicate track 1 of user playlist "mylist2" to playlist a
play track 1 of playlist a
end tell
What this does is simply create a new playlist, add a couple of tracks to it, and play it. The tracks play in order until finished.
Another way is to put in a delay after the first play command that is based on the duration of the first track:
tell application "iTunes"
activate
play track 1 of user playlist "myliste1"
delay (duration of track 1 of user playlist "myliste1")
play track 1 of user playlist "mylist2"
end tell
It is not very pretty, and after I tried this method for a while, I came up with the first one.
Good luck,
Hi.
Here’s another approach that might suit you:
on playTrack(theTrack)
tell application "iTunes"
play theTrack
repeat while (current track is theTrack)
delay 0.2
end repeat
end tell
end playTrack
tell application "iTunes"
activate
my playTrack(track 1 of user playlist "myliste1")
my playTrack(track 1 of user playlist "mylist2")
stop
end tell