Sh4kr0n

Q: Applescript Save in active document error/problem

0 down vote  favorite  

Hello Community,

 

 

 

I have a problem indicating my AppleScript an error while running.

 

Error: "Microsoft Word" hast found an error: "active document" can´t read." number -1728 from active document

Word Version: Word 2016 Home & Business for Mac

 

Code:

 

tell application "Microsoft Word"
  active
  open "OSX_El_Capitan:Documents:Header:MyHeader.dotx"
  set theDoc to active document
  tell theDoc
  insert file at text object of bookmark "test" file name "OSX_El_Capitan:Documents:Template:DocTemp"
  save in "OSX_El_Capitan:Documents:My Save Name.docx"
  end tell
end tell

 

The scripts has stopped in line "save in..." and marked this line.

The other parts over "save in" are working.

Whether it maybe is a problem active document I do not know.

 

Thanks

OS X El Capitan (10.11.5)

Posted on Sep 9, 2016 6:37 AM

Close

Q: Applescript Save in active document error/problem

  • All replies
  • Helpful answers

  • by Pierre L.,

    Pierre L. Pierre L. Sep 9, 2016 9:41 AM in response to Sh4kr0n
    Level 5 (4,484 points)
    Sep 9, 2016 9:41 AM in response to Sh4kr0n

    You cannot save in a text string. You must save in a file.

    For example:

    set theFile to POSIX file "OSX_El_Capitan/Documents/My Save Name.docx" as alias

    save in theFile

  • by Pierre L.,

    Pierre L. Pierre L. Sep 9, 2016 10:01 AM in response to Sh4kr0n
    Level 5 (4,484 points)
    Sep 9, 2016 10:01 AM in response to Sh4kr0n

    To be sure to have the right posix path, just write

         set theFile to POSIX file "" as alias

    in the Script Editor window. Then drag and drop the file between the quotes.

  • by Sh4kr0n,

    Sh4kr0n Sh4kr0n Sep 12, 2016 1:07 AM in response to Pierre L.
    Level 1 (4 points)
    Mac OS X
    Sep 12, 2016 1:07 AM in response to Pierre L.

    Hello Pierre L, thanks for your answer.

     

    If the document already exists, the script back to me no errors.

    In this case, the text will be written to the file but not saved. And I think that he opens a separate file.


    If the document does not exists, the script back to me one error.

    error "file \":OSX_El_Capitan:Documents:My Save Name\" can not be converted to type alias." number -1700 from file ":OSX_El_Capitan:Documents:My Save Name.docx" to alias

     

    Current code:

    tell application "Microsoft Word"
      active
      open "OSX_El_Capitan:Documents:Header:MyHeader.dotx"
      set theDoc to active document
      tell theDoc
        insert file at text object of bookmark "test" file name "OSX_El_Capitan:Documents:Template:DocTemp"

        set theFile to POSIX file "/Documents/My Save Name.docx" as alias

        save in theFile

      end tell

    end tell

  • by Pierre L.,

    Pierre L. Pierre L. Sep 12, 2016 6:02 AM in response to Sh4kr0n
    Level 5 (4,484 points)
    Sep 12, 2016 6:02 AM in response to Sh4kr0n

    Since I never use Microsoft Word, I can't be of much help.

    Try just removing “as alias”.

  • by Sh4kr0n,

    Sh4kr0n Sh4kr0n Sep 12, 2016 6:54 AM in response to Pierre L.
    Level 1 (4 points)
    Mac OS X
    Sep 12, 2016 6:54 AM in response to Pierre L.

    When I execute the script without "as alias" - the script returns no errors, but word open the "save as"-part and set the document name as the text.