3

We use AppleScript to create MS Word documents, which also included pictures. This works fine with Word 2011, but I run into problems with Word 2016.

When opening files with Word 2016 via AppleScript, a "Grant File Access" dialog window pops up. This probably has to do with sandboxing. For opening documents I fixed it by passing a file-object to the open method:

    tell application "Microsoft Word"
        open "path:to:some:file.docx" --Grant File Access dialog
        open file "path:to:some:file.docx" --No dialog, success!

However, when inserting a picture, I can't seem to find a way to pass a file-object. I use this code:

    set imageFile to choose file
    tell application "Microsoft Word"
        open file someFilePath
        tell document someFileName
            make new inline picture at before text object of cell 1 of row 1 of table 1 ¬
              with properties {file name:(imageFile as text), save with document:true}

The property file name doesn't accept a file-object, and there is no property file.

Is there a way to get rid of this dialog?

  • 1
    I had slightly different problem: compare active document path "path:to:file.docx". To solve the problem I had to add "as POSIX file" at the end of the path: compare active document path "path:to:file.docx" as POSIX file – JohnnyAW Jan 29 '18 at 12:16

You must log in to answer this question.

Browse other questions tagged .