Hi,
An applet generates lists of items and corresponding dates in long format and 24 hour time.
Stripping the item names and description, I get a list of dates as text in long format like this:
set dateList to {¬
"Wednesday, 1 August 2012 02:37:08", ¬
"Wednesday, 31 December 2014 06:56:22", ¬
"Sunday, 17 June 2012 01:19:09", ¬
"Wednesday, 31 December 2014 15:31:20", ¬
"Tuesday, 21 March 2006 22:44:50"}
The lists can be as long as about 200 dates.
The sorted list must maintain the date and time format.
I have had no luck searching this site and others.
Please, how can such a list be sorted by date and time, most recent on top?
this is a AppleScriptObjC solution (usable in Mavericks and higher)
It creates a list of records containing the string value and date value, sorts the list by date and returns the string values
use framework "Foundation"
set dateList to {"Wednesday, 1 August 2012 02:37:08", ¬
"Wednesday, 31 December 2014 06:56:22", ¬
"Sunday, 17 June 2012 01:19:09", ¬
"Wednesday, 31 December 2014 15:31:20", ¬
"Tuesday, 21 March 2006 22:44:50"}
set dateFormatter to current application's NSDateFormatter's alloc()'s init()
dateFormatter's setDateFormat:"EEEE, d MMMM yyyy HH:mm:ss"
set dateRecords to {}
repeat with i from 1 to count dateList
set dateString to item i of dateList
set end of dateRecords to {stringValue:dateString, dateValue:dateFormatter's dateFromString:dateString}
end repeat
set theData to current application's NSArray's arrayWithArray:dateRecords
set theDescriptor to current application's NSSortDescriptor's sortDescriptorWithKey:"dateValue" ascending:false
set sortedData to theData's sortedArrayUsingDescriptors:{theDescriptor}
set sortedDateList to (sortedData's valueForKey:"stringValue") as list
--> {"Wednesday, 31 December 2014 15:31:20", "Wednesday, 31 December 2014 06:56:22", "Wednesday, 1 August 2012 02:37:08", "Sunday, 17 June 2012 01:19:09", "Tuesday, 21 March 2006 22:44:50"}
In Mavericks the code must be saved as script library in ~/Library/Script Libraries
In Yosemite the code can be used directly in Script Editor
Many thanks Stefan,
Now, I don’t have any excuse left for finally biting the bullet and delving into AppleScriptObjC.
I do have Yosemite to make it easier. Thanks again for your kind but decisive nudge.