我正在开发 OSX,Xcode 8.2。目标-C。我使用脚本桥来处理 Adobe InDesign。我有一个很长的 AppleScript,我想用 Scripting-Bridge 将其转换为 Objective-C,以利用其后台任务的可能性。
为了更好地理解,让我向您展示之前 applescript 的部分:
tell application "Adobe InDesign CC 2017"
tell active document
-- grep setup done before
find grep
end tell
end tell
苹果脚本中的结果:
{
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"
}
如果我想在我执行的applescript中获取字符串(注意“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"
在objective-c中翻译的方法:
// document is an instance of the SBApplication indesign
[document findGrepReverseOrder:NO];
结果显示:
(
"<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)>"
)
看起来每个 AdobeInDesignCC2017TextCtxt 对象都包含两个 appleeventdescriptor 来标记单词的位置和长度。我需要访问它们以提取信息。我检查了h。文件,但找不到像在 applescript 中一样使用“作为字符串”提取文本的方法。如何访问描述符?任何想法表示赞赏。