Mac iWork /页面自动化

时间:2020-03-05 18:41:05  来源:igfitidea点击:

Microsoft Office有一个丰富的脚本模型,而Apple iWork则没有,尤其是字处理器Pages。尽管有一些AppleScript钩子,但看来最好的方法是处理基础XML数据。

事实证明这很丑陋,因为(例如)分页符存储在XML中。因此,例如,我们有以下内容:

... we hold these truths to be self evident, that </page>
<page>all men are created equal, and are ...

因此,如果要添加或者删除文本,则必须根据页面上文本的大小来移动开始/结束标签。如果不计算页面可以容纳的单词数,这几乎是不可能的,这似乎非常不雅致。

有人对此有任何想法吗?

解决方案

回答

我建议修改基础XML文件是"有害的"。特别是如果我们尚未检查文档是否打开!

我快速浏览了"页面脚本字典",它看起来很全面。这是一个条目的一部分:

document?n [inh. document > item; see also Standard Suite] : A Pages document.
  
  elements
  
  contains captured pages, character
  styles, charts, graphics, images,
  lines, list styles, pages, paragraph
  styles, sections, shapes, tables, text
  boxes.
  
  properties
  
  body text (text) : The main text flow of the document.
  
  bottom margin (real) : The bottom margin of the publication.
  
  facing pages (boolean) : Whether or not the view is set to facing
  pages.
  
  footer margin (real) : The footer margin of the publication.
  
  header margin (real) : The header margin of the publication.
  
  id (integer, r/o) : The unique identifier of the document.
  
  ...

所以,我想我想知道AppleScript无法完成的工作是什么?

回答

iWork '09的最新版本包括非常全面的Applesript挂钩,尽管不完整,尤其适用于页面。 Applescript的使用应该比修改基础文件更安全,更稳定。