[delurk]
Relevant to your interests: Over the last few weeks I’ve been quietly putting together an AppleScript ‘standard library’ which I’m going to upload to Radar as a ‘bug patch’ in the vague hope that someone at Apple with more sense than Sal’s lot has the wits to stick it into 10.12/10.13 as it’s ridiculous that after 20+ years AS still doesn’t have a stdlib worth squat. I’m just about through the features list and am currently getting caught up on unit tests and documentation. A lot of it’s still underdocumented and buggy as anthills, but the List library now has pretty good test coverage and I’ve shaken a lot of bugs out of it over the weekend, so you may want to give it a go. Download the zip file from github, and drop the libraries into your Script Libraries folder. Touch wood you should then be able to sort your list of records as follows:
script ModDateComparator
-- orders a list of {index:., modDate:., noteTitle:.} records by modDate property
property parent : (date comparator)
to makeKey(aRecord)
return continue makeKey(modDate of aRecord)
end makeKey
end script
sort list noteRecList using ModDateComparator
More complex ordering requirements, e.g. to order on multiple fields, can be composed as needed. (You’ll find it easier if you start with a list of lists rather than a list of records, but you can adapt it to extract record properties if necessary.) See the List library’s dictionary for more (rough) examples, e.g. see the list comparator
constructor for examples of sorting on multiple fields. Any problems, requests for documentation improvements, etc, please message me via GitHub.
…
BTW, I’ve never used Evernote so don’t know its dictionary, but retrieving thousands of property values from it one one by one is liable to impact performance no matter what else you do, due to the overhead in sending and processing thousands of Apple events. If possible, you should retrieve each property from all elements at once:
tell app "SomeApp"
tell every element whose <whatever>
set allTitles to its title
set allModDates to its modification date
-- etc.
end tell
end tell
Bear in mind that Apple event IPC is RPC plus simple first-class relational queries, not OOP, so it’s often quicker to send a small number of AEs containing complex queries that process lots of elements at once, rather than retrieving a list of element specifiers then iterating over it to manipulate one element at a time. How well this works in practice depends a lot on how well the app’s Apple Event Object Model is implemented, so if a command like find notes
returns a list of specifiers then you’re SOOL unless you can replace it with an every note whose .
clause that performs the same filtering operation.
Caveat: Always performance profile a slow script before trying to optimize it, so that you accurately identify the real bottlenecks and aren’t just wasting your time randomly “optimizing” code that isn’t actually causing the performance problem. The TestTools library includes a basic timer object you can use to time portions of your script manually. (I’d really like to provide an osaprofile
tool that times all handlers automatically, but the OSA API and its documentation is woefully inadequate on the details needed to do this, and I’m pretty much out of time.)
[/delurk]