在Word 2016中使用AppleScript打开文件

时间:2017-11-21 22:29:15

标签: ms-word applescript

以下Applescript代码与Word 2008一起工作(即,如果存在,则打开文档)。

如果应用程序尚未运行,则无法与Word 2016一起使用。

tell application "Microsoft Word"
    open file "Macintosh HD:Users:username:Stuff.docx"
end tell

Word 2016打开一个对话框,提示该文件不存在,然后在以下目录中创建并打开文件:

/Users/username/Library/Containers/com.microsoft.Word/Data

该文件的名称在Finder中显示如下:

Macintosh HD/Users/username/Stuff.docx

在终端中如下:

~$cintosh HD:Users:edimark:Rien.docx

2 个答案:

答案 0 :(得分:1)

只需添加launchactivate即可。但我无法解释为什么需要这样做。

tell application "Microsoft Word"
   launch
   open file "Macintosh HD:Users:username:Stuff.docx"
end tell

activate会将应用程序带到前面; launch不会。

答案 1 :(得分:0)

Word过去仅使用tell而不是激活这一事实是Word的问题,而不是AppleScript。

如前所述,使用启动或激活是AppleScript正确向应用程序发送消息的必要条件。