我正在尝试使用 Scripting Bridge 从我的应用程序中修改现有的 Pages 文档。我已经遵循文档中提到的所有步骤:我创建了一个头文件并彻底检查了它,但我就是不知道如何做到这一点。
我基本上是在尝试进行搜索替换:我有一个字符串列表,我想用这些字符串替换一些搜索值。问题是我无法弄清楚 PagesWord 类是如何工作的。我只想从中获取一个字符串,并将其与我的搜索值进行比较。我目前必须遵循以下代码:
PagesApplication *pages = [SBApplication applicationWithBundleIdentifier:@"com.apple.iWork.Pages"];
PagesDocument *document = [pages open:inputURL];
PagesText *bodyText = [document bodyText];
SBElementArray *words = [bodyText words];
NSLog([NSString stringWithFormat:@"%d words.", [words count]]);
for (PagesWord *word in [bodyText words]) {
NSLog((NSString *)word);
}
在最后 3 行之前一切正常:打开正确的 Pages 文档并记录字数,但字符串不是:我只看到异常消息。我也尝试使用 PagesWord 的属性,但我也遇到了同样的问题......
谁能帮我?