脚本桥 Objective-c PagesWord

发布于 2024-12-10 07:53:51 字数 713 浏览 7 评论 0原文

我正在尝试使用脚本桥从我的应用程序中修改现有的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2024-12-17 07:53:51

要替换我使用的单词:

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"];}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文