脚本桥 Objective-c PagesWord
我正在尝试使用脚本桥从我的应用程序中修改现有的 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 行:打开正确的页面文档并记录字数,但字符串不是:我只看到异常消息。我也尝试使用 PagesWord 的属性,但我遇到了同样的问题...
任何人都可以帮助我吗?
I'm trying to modify an existing Pages document from within my application using the Scripting Bridge. I've followed all steps mentioned in the documentation: I created a header file and thoroughly examined it, but I just can't figure out how how to do this.
I'm basically trying to do a search an replace: I've got a list of strings and I want to replace some search values with those strings. The problem is that I just can't figure out how the PagesWord class works. I just want to get a string from it and it compare it to my search value. I currently have to following code:
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);
}
Everything works well until the last 3 rows: the correct Pages document is opened and the word count is logged, but the string isn't: I just see exception messages. I also tried to work with the properties of PagesWord, but I have the same problems then...
Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要替换我使用的单词:
for (PagesWord *word in [bodyText Words]) {
[word select];
[[document Selection] setTo:@"我的新值"];}
To replace the word i use:
for (PagesWord *word in [bodyText words]) {
[word select];
[[document selection] setTo:@"my new value"];}