1

I have this script for ensuring that every track in a given smart playlist is both shufflable and bookmarkable.

The script is inteded to be launched via launchd.

All of this is set up fine except that the script exhibits strange behavior. When you run it, some of them succeed but the majority seem to fail due to error code -1731. Subsequent runs the same behavior happens until you have no more shufflable and bookmarkable tracks.

I would expect that if the code errors on the first run it would keep erroring but that's not what happens.

What's happening here?

1
  • I would bet that the failure isn't random.
    – Daniel
    Commented Aug 22, 2013 at 12:14

2 Answers 2

4

Add an explicit get to resolve the reference to the tracks:

tell application "iTunes"
    repeat with t in (get tracks of playlist "Listen Smart" where shufflable is false)
        set shufflable of t to true
    end repeat
    repeat with t in (get tracks of playlist "Listen Smart" where bookmarkable is false)
        set bookmarkable of t to true
    end repeat
end tell

Try running a script like this:

tell application "iTunes"
    repeat with t in (tracks of playlist "Listen Smart" where shufflable is false)
        t
    end repeat
end tell

If the playlist has three tracks where shufflable is false, the result at the end will be something like item 3 of every track of playlist "Listen Smart" of application "iTunes" whose shufflable = false. If you set the shufflable of the first two tracks to true inside the repeat loop, there won't be an item 3 where shufflable is false.

If you replace repeat with t in (tracks with repeat with t in (get tracks, the result at the end will be something like item 3 of {file track id 54774 of user playlist id 54771 of source id 73 of application "iTunes", file track id 54775 of user playlist id 54771 of source id 73 of application "iTunes", file track id 54776 of user playlist id 54771 of source id 73 of application "iTunes"}.

2
  • I think I understand now. I believe what you're pointing out is that the list I'm consuming with the repeat … in is actually mutating under the hood but the counter that I'm repeating over is not so I'm actually erroring when I consume half the list each time because half the last is now gone. Could you make that a little more explicit in your answer if that's what you're going for? It took me a little while to see it and I think other people would have the same difficulty.
    – Tim Visher
    Commented Aug 23, 2013 at 12:08
  • @TimVisher I edited the answer. The list is not mutating, but it contains references like item 123 of every track of playlist "Listen Smart" of application "iTunes" whose shufflable = false.
    – Lri
    Commented Aug 23, 2013 at 18:58
0

As a complete hack, this seems to do the trick.

Note that it's super unsatisfying so I'm still very interested in hearing a better response.

You must log in to answer this question.

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