Pal Pal - 9 months ago 110
AppleScript Question

Open file using AppleScript in Word 2016

The following Applescript code works (i.e. opens the document, provided it exists) with Word 2008.

It does not work with Word 2016 if the application is not already running.

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


Word 2016 opens a dialog saying that the file does not exist, then creates and opens a file in the following directory:

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


That file’s name appears as follows in the Finder:

Macintosh HD/Users/username/Stuff.docx


And as follows in the Terminal:

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

Pal Pal
Answer Source

Just add launch or activate. I can’t explain why this is needed, though.

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

activate will bring the app to the front; launch won’t.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download