Created
January 26, 2020 10:27
-
-
Save khanlou/d165bb6d660c324ca2cf52c07b8e074b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Music" | |
-- Get list of albums, the fast way... | |
set albumsWithDups to (album of every track) | |
set albumsNames to my removeDuplicates(albumsWithDups) | |
-- Check each album | |
repeat with currentAlbum in albumsNames | |
set albumSongs to (every track of library playlist 1 whose album is currentAlbum) | |
-- Check track count | |
if ((the count of albumSongs) is equal to (track number of the last item of albumSongs) and the (count of albumSongs) is greater than 3) or ((track number of the last item of albumSongs) - (the count of albumSongs) is less than 3 and the (count of albumSongs) is greater than 8) then | |
repeat with songx in albumSongs | |
duplicate songx to playlist "Full Albums" | |
end repeat | |
end if | |
end repeat | |
end tell | |
on removeDuplicates(lst) | |
-- from http://applescript.bratis-lover.net/library/list/#removeDuplicates | |
local lst, itemRef, res, itm | |
try | |
if lst's class is not list then error "not a list." number -1704 | |
script k | |
property l : lst | |
property res : {} | |
end script | |
repeat with itemRef in k's l | |
set itm to itemRef's contents | |
-- note: minor speed optimisation when removing duplicates | |
-- from ordered lists: assemble new list in reverse so | |
-- 'contains' operator checks most recent item first | |
if k's res does not contain {itm} then ¬ | |
set k's res's beginning to itm | |
end repeat | |
return k's res's reverse | |
on error eMsg number eNum | |
error "Can't removeDuplicates: " & eMsg number eNum | |
end try | |
end removeDuplicates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment