尝试使用用户输入自动保存新的word文档

时间:2014-05-20 00:03:42

标签: ms-word applescript

我正在使用Applescript而我无法使其工作,可能是因为我对变量的理解非常有限。无论如何,这是我到目前为止的剧本:

tell application "Microsoft Word"
activate

end tell

display dialog "Input Document Name" default answer ""
set answer to text returned of result

tell application "Microsoft Word"
    create new document
    save document as answer

end tell

感谢任何帮助,甚至重定向到相关帖子。感谢。

1 个答案:

答案 0 :(得分:0)

您必须密切关注相关的Applescript词典,并确定Applescript期望的内容。在这种情况下,您需要"另存为"。如果你向上看"另存为"在Word applescript字典中,你看到的第一件事是

save as document
[file name text]

让我们尝试将您拥有的内容插入其中。而不是"将文档保存为答案"你至少需要

save as document file name answer

但这还不够,因为"文件"它本身并不是任何东西的名称,也不是对任何文件的引用。此时,您需要查找"创建新文档"确实

create new document
(various parameters)
-> document

所以你可能需要的是

set theDocument to create new document
save as theDocument file name answer

它并不总是那么直截了当,而且并非字典中的一切都是显而易见的。例如,我不认为字典会告诉您,当word创建新文档时,它通常会成为"活动文档"。如果您知道在所有可能的环境中,这就是Word所做的,您也可以使用

create new document
save as active document file name answer

但第一种方法是IMO更强大。

相关问题