• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
applescript to sort a list of tracks by most frequently played in the past 7 days
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

applescript to sort a list of tracks by most frequently played in the past 7 days


  • Subject: applescript to sort a list of tracks by most frequently played in the past 7 days
  • From: Adam Ochonicki <email@hidden>
  • Date: Wed, 26 Jul 2006 14:38:40 -0400

Hi, I need some help with this applescript. What I need to do is:

1. pull all tracks from the Library that have been played in the past week
2. sort tracks by most frequently played and condense the list to the top ten most frequently played tracks
3. save to itunes playlist
4. export that playlist as an XML document.
5. Upload that XML file to a server

So far I have been successful in 1, 3 and 5. 

I can't figure out how to sort by the top ten most frequently played songs or export a playlist to an XML document. Can anyone offer any help? 

Thanks

Below is a portion of my code without the uploading script because I am certain that works as-is:

set startDateUn to the (current date) - (7 * days)
set endDateUn to the current date
set masterList to "Library"
set startDate to my format_date_using(startDateUn, "/", {"MM", "DD", "YY"})
set endDate to my format_date_using(endDateUn, "/", {"MM", "DD", "YY"})
set recentlyPlayed to ("Played " & startDate & " - " & endDate)
set topTenList to {}

tell application "iTunes"
--create folder for these playlists if one doesn't exist
if not (exists folder playlist "Top Ten") then
make new folder playlist with properties {name:"Top Ten"}
end if


if exists playlist recentlyPlayed then
delete playlist recentlyPlayed
make new playlist in folder playlist "Top Ten" with properties {name:recentlyPlayed}
else
make new playlist in folder playlist "Top Ten" with properties {name:recentlyPlayed}
end if


copy (tracks in playlist masterList whose played date > startDateUn and played date < endDateUn) to playlist recentlyPlayed
end tell

on format_date_using(this_date_record, delimiter_string, format_list)
-- get numeric day
set numeric_day to day of this_date_record
-- get month
set month_name to month of this_date_record
-- convert month to number
set list_of_months to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item i of list_of_months is month_name then
set numeric_month to i
exit repeat
end if
end repeat
-- get numeric year as text
set numeric_year to year of this_date_record as string
set formatted_date to ""
-- count number of items in list
set item_count to count of format_list
-- parse format list
repeat with i from 1 to item_count
set this_item to item i of format_list
if this_item is "D" then
set formatted_date to formatted_date & numeric_day as string
else if this_item is "DD" then
if numeric_day is less than 10 then set numeric_day to ("0" & (the numeric_day as string))
set formatted_date to formatted_date & numeric_day as string
else if this_item is "M" then
set formatted_date to formatted_date & numeric_month as string
else if this_item is "MM" then
if numeric_month is less than 10 then set numeric_month to ("0" & (the numeric_month as string))
set formatted_date to formatted_date & numeric_month as string
else if this_item is "YY" then
set formatted_date to formatted_date & ((characters 3 thru 4 of numeric_year) as string)
else if this_item is "YYYY" then
set formatted_date to formatted_date & numeric_year
end if
if i is not item_count then
-- add delimiter
set formatted_date to formatted_date & delimiter_string as string
end if
end repeat
return formatted_date
end format_date_using


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: AppleScript cache and writing a scriptable app
  • Next by Date: Desktop Picture not persist across reboot
  • Previous by thread: Re: AppleScript cache and writing a scriptable app
  • Next by thread: Re: applescript to sort a list of tracks by most frequently played in the past 7 days
  • Index(es):
    • Date
    • Thread