Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AppleScript to get iTunes to sort albums by release date
-- Fix albums display order
-- Changes the "sort album" field, to ensure that albums get displayed in chronological order on iPods.
-- CC-BY-NC 2011, Jean-Karim Bockstael,
tell application "iTunes"
-- input checking
if selection is {} then
display dialog "You must select at least a track"
return
else
set selected_tracks to selection
repeat with a_track in selected_tracks
if a_track's album = "" then
display dialog "All tracks must have their Album field filled"
return
end if
if a_track's year = "" then
display dialog "All tracks must have their Year field filled"
return
end if
end repeat
set cur_album to album of item 1 of selected_tracks
set cur_year to year of item 1 of selected_tracks
if length of selected_tracks >= 1 then
repeat with a_track in selected_tracks
if a_track's album is not equal to cur_album then
display dialog "All tracks must share the same album name"
return
end if
if a_track's year is not equal to cur_year then
display dialog "All tracks must share the same release year"
return
end if
set cur_album to a_track's album
set cur_year to a_track's year
end repeat
end if
-- actual work
repeat with a_track in selected_tracks
set a_track's sort album to (a_track's year as string) & " " & (a_track's album as string)
end repeat
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment