@msteffens This is amazing and is immediately useful to me. Thank you for sharing it. Even more surprising that we seem to have very similar approaches to annotating pdfs!
Thank you!
Now… I hate to be “that guy” (but here we go…) Where you use “@” symbols to denote your tags, I just put mine on a new line that starts with “Tags:” followed by comma-separated values that represent the tags. I cannot figure out how to modify your script to capture these. If you’re willing, any chance you could suggest how this could be done? Thanks in advance for any advice you’re willing to share.
I think the easiest approach would be to inject a “filter” method which transforms your markup syntax into the one used by the script. To do so, please open the script in Script Editor and search for this line:
set annotText to (pdfAnnotation's annotText)
Insert following line in front of the above line:
set aComment to my preprocessAnnotationComment(aComment)
Then, at the very bottom of the script, insert this script handler:
-- Transforms the given annotation comment/notes (which may contain custom markup
-- syntax) into a Keypoints-style format that's supported by this script and returns it.
on preprocessAnnotationComment(aComment)
-- convert tags
-- input: a separate line that starts with “Tags:” followed by comma-separated values that represent the tags
set transformedLines to {}
set tagsLineRegex to "(?<=^|[\\r\\n])Tags:\\s*"
set tagDelimiterRegex to "(?<=^<|[\\r\\n]<)\\s+|\\s*,\\s*"
repeat with aLine in paragraphs of aComment
if (KeypointsLib's regexMatch(aLine, tagsLineRegex)) is not "" then
set aLine to KeypointsLib's regexReplace(aLine, tagsLineRegex, "< ")
set aLine to KeypointsLib's regexReplace(aLine, tagDelimiterRegex, " @")
end if
copy aLine as text to end of transformedLines
end repeat
set transformedString to KeypointsLib's mergeTextItems(transformedLines, linefeed) & linefeed
return transformedString
end preprocessAnnotationComment
I’m sure this could be done in a better way but it should get the work done.