[英]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.