I’ve been developing an AppleScript application that - among other things - has to get references to page items in Adobe InDesign.
I have a working version written using AppleScript Studio, but with further development needed, I decided to rewrite the application so as it was primarily in Objective-C and executing short scripts, obtaining needed values, storing the values in Cocoa objects and then passing these values on to other scripts as required.
I figured this would give me an application that was easier to maintain and execute faster than having all the management and GUI code in AppleScript.
Executing scripts from within Objective-C is fairly straightforward by obtaining an NSAppleScript reference to a script and returning values from that script to an NSAppleEventDescriptor object. There seems to be no way to directly pass arguments to a script using an NSAppleScript object, but this can be got around by having the script execute the “call method” command to obtain the needed arguments from a Cocoa object.
My problem is this-
I need to access an InDesign document and obtain references to items on a page. They are returned in the form of image id 144 of rectangle id 143 of page id 119 of spread id 114 of document “Untitled-1”.
I obtain an NSAppleScript reference and execute script A, query InDesign, and have the references to page items returned to an NSAppleEventDescriptor which is then stored in a Cocoa object. A little later I execute script B with uses 'call method" to obtain these references to page items and then present them back to InDesign, but the best I can do is an NSCannotCreateScriptCommandError.
I’ve done tests getting script A to return values which are stored in a Cocoa object and the having script B access those values. Simple values - no problem, strings - no problem, lists of strings - no problem, records - no problem.
But somehow these references to InDesign page items don’t seem to maintain their integrity. Has anyone got any pointers as to where I’m going wrong and how to get around this problem?