I am working on OSX, Xcode 8.2. Objective-C. I use scripting bridge to adress Adobe InDesign. I have a pretty long AppleScript i want to translate to Objective-C with Scripting-Bridge to take advantage of its background-task possibilities.
For better understanding let me show you the part from applescript before:
tell application "Adobe InDesign CC 2017"
tell active document
-- grep setup done before
find grep
end tell
end tell
The result in applescript:
{
text from character 294 to character 298 of story id 1354 of document id 5 of application "Adobe InDesign CC 2017",
text from character 140 to character 144 of story id 1377 of document id 5 of application "Adobe InDesign CC 2017"
}
If i want to get the string in applescript i perform (notice the "as string"):
text from character 294 to character 298 of story id 1354 of document id 5 of
application "Adobe InDesign CC 2017" as string
--> "Test1"
The translated method in objective-c:
// document is an instance of the SBApplication indesign
[document findGrepReverseOrder:NO];
The result reads:
(
"<AdobeInDesignCC2017TextCtxt @0x608020a442f0: AdobeInDesignCC2017TextCtxt [<NSAppleEventDescriptor: 'obj '{ 'form':'indx', 'from':'obj '{ 'form':'ID ', 'from':'obj '{ 'form':'ID ', 'from':null(), 'seld':5, 'want':'docu' }, 'seld':1354, 'want':'cflo' }, 'seld':294, 'want':'cha ' }>..<NSAppleEventDescriptor: 'obj '{ 'form':'indx', 'from':'obj '{ 'form':'ID ', 'from':'obj '{ 'form':'ID ', 'from':null(), 'seld':5, 'want':'docu' }, 'seld':1354, 'want':'cflo' }, 'seld':298, 'want':'cha ' }>] of AdobeInDesignCC2017Story id 1354 of AdobeInDesignCC2017Document id 5 of application \"Adobe InDesign CC 2017\" (696)>",
"<AdobeInDesignCC2017TextCtxt @0x608020a44140: AdobeInDesignCC2017TextCtxt [<NSAppleEventDescriptor: 'obj '{ 'form':'indx', 'from':'obj '{ 'form':'ID ', 'from':'obj '{ 'form':'ID ', 'from':null(), 'seld':5, 'want':'docu' }, 'seld':1377, 'want':'cflo' }, 'seld':140, 'want':'cha ' }>..<NSAppleEventDescriptor: 'obj '{ 'form':'indx', 'from':'obj '{ 'form':'ID ', 'from':'obj '{ 'form':'ID ', 'from':null(), 'seld':5, 'want':'docu' }, 'seld':1377, 'want':'cflo' }, 'seld':144, 'want':'cha ' }>] of AdobeInDesignCC2017Story id 1377 of AdobeInDesignCC2017Document id 5 of application \"Adobe InDesign CC 2017\" (696)>"
)
It looks like each AdobeInDesignCC2017TextCtxt object contains two appleeventdescriptors to mark the position of the word and the length. I need to access them to extract the information. I checked the h. file but cannot find a method to extract the text like in applescript with "as string". How can i access the descriptors? Any idea appreciated.
I would recommend using the AppleScript-ObjC bridge, which lets you call AppleScript handlers directly from ObjC same as you call Cocoa methods. Scripting Bridge is riddled with crippled and missing features, and very prone to application incompatibilities, especially with older Carbon-based apps like Adobe's. It works up to a point, and then you're screwed. (I know of one guy who tried converting all his Adobe scripts to SB, only for the whole lot suddenly to stop working on a minor update.)
The only competent alternative to AppleScript is py-appscript/SwiftAutomation (I use py3-appscript for high-end Illustration automation), but I no longer provide public support for those due to Apple's screwing about, so you'd be on your own. AppleScript is a ghastly language, but at least it's officially supported [cough] and its Apple event bridge is second to none. Here's a quick how-to on calling AS from ObjC. As long as you call your AppleScript handlers on a single thread, the ObjC portions of your program can take advantage of threads, GCD, etc. It's really simple, almost entirely painless, and allows each language to do what it does best.