Skip to content

Instantly share code, notes, and snippets.

@dayfuaim
Forked from jkbockstael/AlbumsOrder.scpt
Last active March 7, 2020 13:00
Show Gist options
  • Save dayfuaim/a0f009efd6f3b62745185e62b72a97dd to your computer and use it in GitHub Desktop.
Save dayfuaim/a0f009efd6f3b62745185e62b72a97dd to your computer and use it in GitHub Desktop.
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