dougscripts.com

January 11 2016 - 6:15 am

Playlist Time to Playlist Name

Here's a simple script that was inspired by a question Kirk got asked in his Ask the Tunes Guy column in Macworld last week. A user lamented that the playlist length (that is, its total time) is not available in the Music app on iOS. Kirk recommended adding this information to the playlist name in iTunes and then re-syncing. A good solution but kind of a chore. This script will do the renaming part for you.

Just select a playlist in iTunes and launch the script. It will display a confirmation dialog and then rename the playlist by appending the time length to its current name:

tell application "iTunes"

try

set thisPlaylist to view of front browser window

if special kind of thisPlaylist is none then

set newName to (my fixName(thisPlaylist's name) & " | " & thisPlaylist's time) as text

-- confirm

try

display dialog "Rename selected playlist to:" & return & return & newName

on error

return

end try

tell thisPlaylist to set name to newName

else

error

end if

on error m number n

try

display dialog "Can't change the selected playlist's name." buttons {"OK"}

end try

return

end try

end tell

to fixName(n)

if n does not contain "|" then return n

return text 1 thru ((offset of "|" in n) - 2) of n

end fixName

Couple of things to note: only user-created scripts (plain and Smart) can be affected. Also the script uses the "pipe" character to separate the actual name with the appended data. When you run the script again on a playlist that has previously been affected by the script, it uses the "|" as a marker to erase the appended text; thus, the playlist name can be updated if the contents changes at a later date. So, if you happen to already use "|" in your playlist names you may have a problem. You can edit the script in Script Editor to change each of the occurrences of "|" to some other text character that you aren't likely to use.

Site contents © 2001 - 2024 (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 be interrupting the one who is doing it.