Hi, folks - I’ve been digging around for the language that would tell “iTunes” to sort the current playlist by “Last Played” descending, but I can’t for the life of me find any “SORT” instruction information. Is Applescript able to tell iTunes to sort by a column during a script, or will I always have to do it manually?
thanks!
I think you are stuck doing it manually. It appears that the browser window functions, few though they are, are primarily read-only. I am also unsure if even GUI scripting would help tag those little triangles above each column for sorting purposes anyway.
That said, any playlist is potentially sortable via AppleScript. I am not much of a sorting guy myself (at least via AppleScript), but I know there are a few bubble sort and other algorithms out there for perusal. It actually might be a fun excercise to see if one could take a playlist, let the user select the sorting field, and have the tracks line up according to the sort. Hmmmm…
Hi,
I made a script last night, but lost all my scripts and was too tired to look in my books, so had to make up a sorting algorithm. I think it’s something like insertion sort. Unfortunately, the Script Editor crashes if I use it on the library playlist. Probably because the lists are too big. I’m still thinking of a better way to handle the big library playlist. Here’s the one that crash on the library playlist, but works on 150 tracks in a playlist.
tell application “iTunes”
activate
set browser_win to first browser window
set cur_view to view of browser_win
tell cur_view
set track_count to (count every track)
set date_list to {date “Monday, January 1, 1900 12:00:00 AM”, date “Friday, January 1, 2100 12:00:00 AM”}
set track_list to {“”, “”}
repeat with i from 1 to track_count
set this_track to track i
set played_date to played date of this_track
if played_date is missing value then
set played_date to date “Tuesday, January 1, 1901 12:00:00 AM”
end if
set date_count to (count date_list)
repeat with j from 1 to date_count
set this_date to item j of date_list
if played_date < this_date then
set temp_dates to items j thru -1 of date_list
set date_list to (items 1 thru (j - 1) of date_list) & {played_date} & temp_dates
set temp_tracks to items j thru -1 of track_list
set track_list to (items 1 thru (j - 1) of track_list) & {location of this_track} & temp_tracks
exit repeat
end if
end repeat
end repeat
end tell
set temp_pl to (make new playlist with properties ¬
{name:“Temp Playlist”})
set track_list to items 2 thru -2 of track_list
add track_list to temp_pl
end tell
Probably Nigel can come up with a good sorter.
gl,
Hi CAS,
The workaround finally came to me. It just popped into my head just now. First, create a playlist. I called it “Played Date Sorted”. Click on the Last Played column and make sure it’s descending. Select a target playlist. Now run this script:
tell application “iTunes”
activate
set bw to first browser window
set cur_pl to view of bw
set sorted_pl to playlist “Played Date Sorted”
delete every track of sorted_pl
duplicate every track of cur_pl to sorted_pl
set view of bw to sorted_pl
play
end tell
First it clears the tracks from playlist “Played Date Sorted”, then it copies the tracks from the one in the browser window to the sorted playlist and plays them in sorted order since that’s how it’s set. I can use this!
gl,