dougscripts.com

February 27 2012 - 10:26 am

Custom Playlist Column Views, Sorta

Here's something I'm often asked which Correspondent Rob Falk put succinctly: "Is there a way to clone a playlist view...other than the Library [using Assimilate View Options]? I frequently need to create a playlist that has a specific set of columns, that are not the same as the library, and was looking for a way to automate that."

There sorta kinda is.

My first thought was to use AppleScript to just duplicate an existing playlist that already had the requisite view settings. (The duplicate command is typically used to copy a track from one playlist to another.) Unfortunately, when iTunes' AppleScript duplicate command is used to copy a playlist it—bafflingly—creates a new untitled and empty playlist using the properties and views of the Music library playlist. Same as just creating a new playlist. That doesn't seem right, does it? You'd think—well, I thought anyway—that using duplicate to copy a playlist would behave the same as the playlist contextual menu command "Duplicate" (control-click or right-click on the name of the playlist):

So, my next thought was...just use "Duplicate". The playlist will be perfectly duplicated, column views and all, and selected in the Source list. Now you'll have a new playlist named the same as the original with a "1" at the end and which is populated with the original's tracks (if it had any). You could create a bunch of playlists with columns set the various ways you like and then "Duplicate" them when you required one. Just rename the new duplicated playlist and delete any tracks. And that part can be automated.

The workflow, then, is to "Duplicate" a playlist manually with the contextual menu command and then run this script right afterwards:

tell application "iTunes"

try

set duplicatedPlaylist to (get view of front window)

set opt to (display dialog "Enter a name for this playlist:" default answer "")

set newName to text returned of opt

if newName is "" then error

tell duplicatedPlaylist

try

delete every track

end try

set name to newName

end tell

reveal (some playlist whose special kind is Music)

reveal duplicatedPlaylist

on error

return

end try

end tell

The duplicatedPlaylist variable will be set to the currently selected playlist—as long as you haven't clicked on something else this will be the one just created with "Duplicate". The script then asks for a new name for the playlist, deletes any tracks from it, gives it the new name, and selects the re-named playlist. I've had the script reveal the Music playlist first so the Source list will scroll to the renamed playlist properly when reveal is subsequently called on it.

This routine works much slicker when you assign this script a keyboard shortcut. Then it's only a matter of firing "Duplicate" with the cursor and then hitting the shortcut to fire the script. Bing-bang.

(I was too lazy to try and figure out if "Duplicate" can be scripted using GUI Scripting. If anyone can tell me about that I'd be obliged.)

I'm hoping that a future release of iTunes will allow the duplicate command to behave the same as "Duplicate".

Site contents © 2001 - 2020 (that's right: 2001) Doug Adams and weblished by Doug Adams. Contact support AT dougscripts DOT com. About.
All rights reserved. Privacy.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc. This site has no direct affiliation with Apple, Inc.
The one who says "it cannot be done" should not interrupt the one doing it.