Applescript Convert Word doc to docx

applescriptms office

I am looking for a way to batch-convert/bulk-convert .doc files into .docx files. I found this TidBITS Talk that references a Redit thread for an AppleScript (AS) and a dead DropBox link for an Automator integration of mentioned AS in a WorkFlow.

However, when I run the script in Automator or Script Editor I get a Syntax ErrorExpected end of line, etc. but found identifier. Inside the script compatibility is highlighted (as being the issue, I guess).

What can be done to correct the error?

Find the new version as suggested by @CJK of the entire script here below:

property theList : {"doc"}

on run {input, parameters}
        set output to {}
        tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path
        repeat with theDoc in input
        tell application "System Events"
            set theFolderPath to the path of theDoc's container
            set theExtension to name extension of theDoc
            set theName to name of theDoc
        end tell
        if theExtension is in theList then
            set l to the length of theName
            set exl to the length of theExtension
            set n to l - exl - 1

            set theFilename to (text 1 through n of theName) & ".docx"

            tell application "Microsoft Word"
                set default file path file path type documents path path theFolderPath
                open theDoc
                set theActiveDoc to the active document
                save as theActiveDoc file format format document file name theFilename without maintain compatibility
                close theActiveDoc
            end tell

            set end of output to the POSIX path of (theFolderPath & theFilename)
        end if
        end repeat

        tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath
        return output
end run

Find here below a screenshot of Script Editor after compilation without the word compatibility (trying to compile the code with this word gives me the same error message as the one at the beginning of this post):
Screenshot of Script Editor after compiling the code.


System used:

  • macOS Catalina 10.15.5
  • MacBook Pro (13", 2019, 2.8 GHz Quad-Core Intel Core i7, 16 GB RAM, Intel Iris Plus Graphics 655 1536 MB)
  • Microsoft Word Version 16.39 (20071300)
  • Script Editor Version 2.11 (208)
  • Automator Version 2.10 (492)

Best Answer