Neat. This is my first time playing with ASObjC.
Using the documentation on PDF Annotations here, I was able to query each annotation’s modification date and sort that way, too.
Script (a slight modification of @mdbraber’s above):
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
use framework "Quartz"
on checkInDT()
tell application id "DNtp"
set theRecords to (selection as list)
repeat with theRecord in theRecords
set thePath to path of theRecord
my readAnnotations(thePath)
end repeat
end tell
end checkInDT
on readAnnotations(thePath)
set thePDF to current application's PDFDocument's alloc()'s initWithURL:(current application's |NSURL|'s fileURLWithPath:thePath)
set theAnnotationsArray to current application's NSMutableArray's new()
repeat with i from 0 to ((thePDF's |pageCount|()) - 1)
set thePage to (thePDF's pageAtIndex:i)
set theAnnotations to thePage's annotations()
repeat with theAnnotation in theAnnotations
log theAnnotation's |modificationDate|()
if theAnnotation's |type|() as string is "Highlight" then
set thePosY to second item of (first item of theAnnotation's |bounds|())
set theHighlight to theAnnotation's |textMarkupString|() as string
set theComment to theAnnotation's |contents|() as string
set theModificationDate to theAnnotation's |modificationDate|()
(theAnnotationsArray's addObject:{page:i, posY:thePosY, highlight:theHighlight, comment:theComment, modificationDate:theModificationDate})
end if
end repeat
end repeat
set theDescriptorPage to current application's NSSortDescriptor's sortDescriptorWithKey:"page" ascending:true
set theDescriptorPosY to current application's NSSortDescriptor's sortDescriptorWithKey:"posY" ascending:true
set theDescriptorModificationDate to current application's NSSortDescriptor's sortDescriptorWithKey:"modificationDate" ascending:true
set theAnnotationsList to (theAnnotationsArray's sortedArrayUsingDescriptors:{theDescriptorModificationDate}) as list
repeat with theAnnotation in theAnnotationsList
log theAnnotation
end repeat
end readAnnotations
Now to see if this will integrate well with the stream annotations workflow… I’m a bit worried that diving into ASObjC will cause the same issues when executing from a smart rule that I saw over here: Smart Rule fails only when triggered as a smart rule: (Can’t get name of «class DTcn» id 1296597 of «class DTkb» id 2.)