2

I'm working on a script to manage my "queue" playlist in iTunes and wanted an easy and fast way to quickly delete all songs in that playlist.

Applescript seemed the best option and I created a little script executable with a keyboard shortcut. However it doesn't seem to work.

This is the relevant part:

tell application "iTunes"
    repeat with t in tracks of playlist "queue"
        tell playlist "queue" to delete t
    end repeat
end tell

The problem is that not all the tracks are deleted, only a part of them. Executing the script multiple times, eventually, deletes all the tracks in the playlist.

0
4

I've had the exact same problem. There's more and more AppleScript bugs in each version of OS X.

If you just want to delete all tracks on a playlist, single expressions like this don't seem to skip any tracks and they're also faster:

tell application "iTunes"
    delete tracks of playlist "untitled playlist"
end tell

If you only need to delete some tracks, something like this might work:

tell application "iTunes"
    repeat
        set tr to tracks of playlist "untitled playlist"
        if tr is {} then exit repeat
        repeat with t in tr
            delete t
        end repeat
    end repeat
end tell
2
  • For some reason the "delete tracks of playlist" expression does not work for me. Script editor returns error "every track of playlist \"Not In Library"\ doesn't understand the "delete" message – RusI Feb 14 '15 at 13:41
  • FYI: the "delete tracks of playlist "..." worked for me. – Gray Jan 12 '16 at 23:29
0

The problem is that not all the tracks are deleted, only a part of them.

Since you are deleting the tracks as you are iterating across them, it might be getting confused. It ends up with approximately half the number of tracks so it looks like it is removing every other one.

tell playlist "queue" to delete t

For the record, the tell playlist "queue" to is being ignored so this is equivalent to just saying delete t.

@user495470 answer is good but this also works for me:

tell application "iTunes"
    delete of (every track of playlist "tmpList")
end tell
0

Note that these examples only delete the song from the playlist, and not from disk.

This has worked for me to do both:

tell application "iTunes"
  set tr to tracks of playlist "a"
  repeat with t in tr
    set a to location of t
    set f to POSIX path of a
    delete t
    do shell script "rm " & quoted form of f
  end repeat
end tell

You must log in to answer this question.

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