简体   繁体   English

JXA / Applescript +页面:从模板创建文档

[英]JXA/Applescript + Pages: Create Document from template

I'm trying to create a Pages file from a Template in JXA. 我正在尝试从JXA中的模板创建Pages文件。

I've successfully got this working in Applescript but am unable to understand the conversion to JXA. 我已经在Applescript中成功完成了这项工作,但是无法理解向JXA的转换。

tell application "Pages"
    activate

    set thisDocument to ¬
        make new document with properties {document template:template "my-template-name"}
end tell

From understanding the function dictionary it really should be something like: 通过了解函数字典,它实际上应该是这样的:

Pages   =  Application("Pages")
Pages.activate()
t       =  Pages.Template("my-template-name") 
// produces: Error on line 2: Error: First parameter passed to Template constructor must be an object

doc = Pages.Document({
    documentTemplate: t
})

doc.make()

But it produces the said error. 但它会产生上述错误。 Other things i tried are: 我尝试过的其他事情是:

t       =  Pages.Template({ 
    name:   "my-template-name",
    id:     "my-template-name"
})
// Produces no error but doesn't open any template

t       =  Pages.Template({}, "my-template-name")
// Same, no error but no template

Really looking forward to some help here. 真的很期待在这里有所帮助。

I just now found out myself. 我现在才发现自己。 To access available templates, use Pages.templates["my-template-name"] . 要访问可用的模板,请使用Pages.templates["my-template-name"]

Resulting in the correct code: 产生正确的代码:

Pages   =  Application("Pages")
t       =  Pages.templates["my-template-name"]
doc = Pages.Document({
    documentTemplate: t
})
doc.make()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 macOS:如何从 AppleScript/JXA 访问实时文本 OCR 功能? - macOS: How to access the Live Text OCR functionality from AppleScript/JXA? 使用 javascript (JXA) 而不是 applescript 处理来自 mac 的电子邮件 - Process emails from mac using javascript (JXA) instead of applescript 如何在macOS上从JXA / JavaScript for Automation脚本运行内联Applescript? - How do you run inline Applescript from a JXA/JavaScript for Automation script on macOS? 通过(JXA / AppleScript)从Chrome中当前网页的内部功能获取值 - Getting values from inner functions of current webpage in Chrome via (JXA / AppleScript) 在.app运行时触发脚本(AppleScript或JXA)? - Trigger a script (AppleScript or JXA) on .app running? 从AppleScript中的PDF文档到JPEG图像 - From PDF document to JPEG images in AppleScript Applescript 命令从 powerpoint 演示文稿中提取模板 - Applescript command to extract template from a powerpoint presentation 使用Java自动化(JXA)创建plist - Use Javascript for automation (JXA) to create a plist 如何使用Applescript从Excel工作表填充页面文件 - How to Populate Pages file from Excel Worksheet using Applescript 使用AppleScript从文本文档中提取两个字符串之间的字符串 - extract string between two strings from text document using AppleScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM