1
votes

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
2

2 Answers

1
votes

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.

0
votes

The fact that Word used to work with just a tell and without being activated is a problem with Word, not AppleScript.

As was replied earlier, using launch or activate is a requirement for AppleScript to properly send a message to the application.