Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iTunes Script - Only Albums. Note that this information is probably out of date. It is being added here for reference/archival purposes and relates to a blog post from 2005
--This script will attempt to compile a playlist of only albums based on user inputted
--values for min. number of tracks per album and min. album duration
--
--Inspired by "Make Album Playlists" by Andrew Mathieson
--And also by TETENAL's script on macnn after he beat me to it
--With info from "Doug's Applescripts for iTunes" www.dougscripts.com/itunes
--
--This script by i5m
--
tell application "iTunes"
set albumList to {}
--Change name below to suit your requirements
set only_albums_playlist to "OnlyAlbums"
--Below can change the source. Used mainly for testing so don't have to work on whole library ("library playlist 1")
set library_source to library playlist 1
display dialog "Enter Min Number of tracks per Album" & return & return & ¬
"No. of Tracks:" default answer ""
set min_number_tracks to the text returned of the result
display dialog "Enter Min Duration of Album in Minutes" & return & return & ¬
"Min Duration:" default answer ""
set min_album_duration to the text returned of the result
display dialog "This may take a long time to run press OK to continue"
--Set fixed indexing. Not utterly sure if this is required here but does no harm
set fx to fixed indexing
set fixed indexing to true
log "Begin part 1, get list of albums"
set source_tracks to (get a reference to library_source)
copy (count library_source's tracks) to idx
repeat with j from 1 to idx
copy track j of source_tracks to thisTrack
set theAlbum to album of thisTrack as string
set add2List to true
if theAlbum is equal to "" then set add2List to false
if albumList contains theAlbum then set add2List to false
if add2List is true then
set albumList to albumList & (theAlbum as string)
log "Added album \"" & (theAlbum as string) & "\" to the list."
end if
end repeat
set fixed indexing to fx
log "Finished Part 1"
log "Begin Part 2: Add Albums to Playlist"
set skipItAll to false
--Don't add blank albums
if theAlbum is "" then set skipItAll to true
if skipItAll is false then
-- does this playlist already exist?
if exists (some user playlist whose name is only_albums_playlist) then
set my_opts to (display dialog "This Playlist exists: " & only_albums_playlist buttons {"Don't Replace", "Replace"} default button 2 with icon 0)
if button returned of my_opts is "Replace" then
set new_playlist to user playlist only_albums_playlist
try
delete every track of new_playlist
end try
else
set skipItAll to true
end if
else
set new_playlist to (make user playlist with properties {name:only_albums_playlist})
end if
if skipItAll is false then
repeat with theAlbum in albumList
set these_tracks to (file tracks of library_source whose album is theAlbum)
set theAlbumDuration to 0
if the (count of these_tracks) is greater than min_number_tracks then
repeat with a_track in these_tracks
set theAlbumDuration to theAlbumDuration + the (duration of a_track)
end repeat
end if
if theAlbumDuration is greater than min_album_duration * 60 then
repeat with a_track in these_tracks
duplicate a_track to playlist only_albums_playlist
end repeat
end if
end repeat
end if
end if
display dialog "Finished making Only Albums playlist!" buttons {"OK"} default button 1 with icon note
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.