How to access comments and their associated text in iWork documents via AppleScript/ScriptingBridge?
Hi all,
I’m developing a Mac OS application with XCode that interacts with iWork documents (Pages, Numbers, Keynote) using ScriptingBridge (and maybe AppleScript). Right now I started with Pages, assuming if it works for Pages, it will likely be similar for Numbers and Keynote.
While I can successfully access and modify the main body text (e.g. the “body text” property in a Pages document), I’m having major difficulties accessing the comments (or annotations) within these documents.
There are many aspects, but right now what I’m trying to achieve:
For a Pages document, I need to scan the document and extract, for each comment:
The content of the comment (i.e. the comment’s text).
The text that is being commented on.
For Numbers, similarly, I need to retrieve the commented cell’s content and the associated comment.
For Keynote, the same as Pages, except I manage to get the Presenter Notes.
Once done, I could replace the content accordingly.
What I’ve tried:
Using AppleScript commands such as:
every comment of document "Test"
Accessing properties like content or range of a comment.
Attempting various syntaxes (including using class specifiers) to force AppleScript to recognize comments.
Using ScriptingBridge in my Swift code, but I couldn’t find any mapping for a “comment” object in the Pages dictionary.
However, all these attempts result in errors such as “cannot convert …” or “this class is not key value coding-compliant for the key …” which leads me to believe that the iWork scripting dictionaries may not expose comments (or annotations) in a scriptable way.
Questions:
Is there a supported way to access the comments (and the associated commented text) in an iWork document via AppleScript or ScriptingBridge?
If so, what is the proper syntax or property name to use? (For example, should I be looking for a class named “comment”, “annotation”, or perhaps something else?)
If direct access via AppleScript/ScriptingBridge is not possible, what alternative approaches would you recommend for programmatically extracting comment data from iWork documents?
I apologize if my post isn't clear, it is translated from French. Any insights or examples would be greatly appreciated. Thank you!