Chibimagic's Weblog

Thinking way too hard about AppleScript

Posted on: December 7, 2008

I was trying to write an applescript to manage my iTunes playlists. I have a manual playlist of the least recently added unwatched TV shows and episodes of TEDTalks, some of which are checked, and I sync this playlist to my iPhone. I wanted a script to remove watched tracks from this playlist and enable additional tracks if there’s space on my iPhone.

At first I was trying to loop through each track of the list, check its play count, and delete if necessary. Then I realized that if you delete track 1, tracks 2 through n become tracks 1 through n-1, and the next track to be processed is track 2. So tracks immediately following a played track would not get processed. Then I was trying to store the index of played tracks to a list, and every time I delete something, loop through the rest of the list and decrease its index by one. Then I started looking at example applescripts and realized there was a single line I could use to copy all played tracks to a list, but there didn’t seem to be a way to delete tracks from a playlist without using its index, which means we still have to deal with the original problem. And then I realized that what I really wanted to do was:

delete every track of playlist "* TV" whose played count > 0

That’s when I realized how backwards and sophisticated applescript is.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

  • Marketing Consultant: You're an great writer. You have brought up some really interesting insights. Just wanted to say fantastic blogs! I know tons of people see your write
  • optical franchise opportunities: Right now it looks like Wordpress is the preferred blogging platform out there right now. (from what I've read) Is that what you are using on your blo
  • startup speaker: Interesting content. A magnificent article. It is very informative and you are obviously very knowledgeable in this area.


%d bloggers like this: