Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Properly sort 'Album by Year' in iTunes and devices' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Properly sort 'Album by Year' in iTunes and devices
Authored by: davechevell on Apr 30, '10 05:51:42AM

x5josh5x: Your script is EXCELLENT. Just what I needed to get my iPhone to sort albums by year before name.

In the spirit of collaboration, I made a few modifications =)

Notes are for intrepid googlers who find their way here:

1 - Sort Album field is now "Artist - Year - Album". This is because the "Albums" view on my iPhone is otherwise impossible to navigate unless i know the year every album in my library was made, and that nifty alphabet-quick-scroll thingie on the right hand side is completely useless when all Sort Album fields begin with a number

2 - Artists & Albums that begin with "A" or "The" (i.e. The Beatles) have these words stripped from the applied Sort Album field (not case sensitive)

3 - Script tests to see if the desired Sort Album field already exists. Running this script for the first time on a library containing thousands of tracks can take a while - running this script a second time to update new songs in your library will be much quicker (my library is about 4000 items - first time running this took a few minutes; second time took 20 - 25 seconds as it found nothing that needed updating)

I modded it purely to run on my own library, so I removed the GUI actions - running this requires opening in AppleScript editor, pasting this in, selecting the desired iTunes tracks (or hitting ⌘ + a to select all). If you're antsy about this kind of stuff, I advise you select one or two tracks in iTunes, run it on them and check the results. You'll feel more comfortable running this on your entire library afterwards.

Random googlers who have ended up here: Since this modifies every song in your library, syncing your iPhone/iPod/iPad the first time after running this is going to take a while, as it has to copy every track over again. Running this script for the first time is also going to take a few minutes at the very least, depending on the size of your music library.

Anyway, here we go. Apologies about bad formatting.. first post, idiot newbie, etc etc. Please direct posting advice this way, I want to give a little back! Thanks again, x5josh5x

tell application "iTunes"
if selection is not {} then
set sel to selection
repeat with this_track in sel
if this_track's sort album does not contain this_track's artist & " - " & this_track's year then
set this_year to this_track's year as string
set this_artist to this_track's artist
if word 1 of this_artist is "a" or word 1 of this_artist is "the" then set this_artist to text ((offset of " " in this_artist) + 1) thru -1 of this_artist
set this_album to this_track's album
if word 1 of this_album is "a" or word 1 of this_album is "the" then set this_album to text ((offset of " " in this_album) + 1) thru -1 of this_album
set this_track's sort album to this_artist & " - " & this_year & " - " & this_album
end try
end if
end repeat
end if
end tell

[ Reply to This | # ]