1 votos

Mensaje de error de AppleScript

Estoy buscando una manera de convertir por lotes/convertir por lotes .doc archivos en .docx archivos. He encontrado esto Charla de TidBITS que hace referencia a un Hilo rojo para un AppleScript (AS) y un enlace muerto de DropBox para una integración en Automator de dicho AS en un WorkFlow.

Sin embargo, cuando ejecuto el script en Automatizador o script Editor Tengo un Error de sintaxis - Esperaba el final de la línea, etc. pero encontró el identificador. Dentro del script compatibility se destaca (por ser el problema, supongo).

¿Qué se puede hacer para corregir el error?

Encuentra la nueva versión sugerida por @CJK de todo el script aquí abajo:

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

A continuación encontrará una captura de pantalla del editor de script después de la compilación sin la palabra compatibility (al intentar compilar el código con esta palabra me da el mismo mensaje de error que el del principio de este post): Screenshot of Script Editor after compiling the code.


Sistema utilizado:

  • MacOS Catalina 10.15.5
  • MacBook Pro (13", 2019, Core i7 de Intel de cuatro núcleos a 2,8 GHz, 16 GB de RAM, gráficos Intel Iris Plus 655 de 1536 MB)
  • Microsoft Word Versión 16.39 (20071300)
  • ScriptEditorial Versión 2.11 (208)
  • Versión 2.10 de Automator (492)

0voto

Mockman Puntos 16

Quieres carpetas Tengo tus carpetas aquí

Para utilizarlo, selecciona una carpeta y ejecuta el script.

Notas: Utilicé Word para abrir cada documento, ya que así era más fácil hacer coincidir el archivo con el contenedor, lo que también debería reducir los problemas con el tiempo que se tarda en abrir varios archivos. No hay ninguna corrección de errores, así que si su selección no es una carpeta .

-- Save all 'doc' within folder structure as 'docx' in same folder
-- Create list of each 'doc' file and its containing folder
set fKind to "Microsoft Word 97 - 2004 document"
tell application "Finder"
    set topFolder to selection as alias
    set refList to a reference to entire contents of topFolder

    set bList to {}
    set docList to every item of refList whose kind is fKind
    repeat with ea in docList
        set c to container of ea as alias as text
        copy {name of ea, c} to end of bList
    end repeat
end tell

-- Open each 'doc', save in same folder, close doc
tell application "Microsoft Word"
    set oldDefaultPath to get default file path file path type documents path

    repeat with b in bList
        -- b in bList example {"filename.doc", "Mac:Users:username:Documents:docFolder1:deepFolder2:"}
        set sName to first item of b
        set sPath to second item of b
        set default file path file path type documents path path (sPath)

        open sPath & sName
        save as document sName file name (sName & "x") file format format
        close document 1 saving no

    end repeat
    set default file path file path type documents path path oldDefaultPath
end tell

AppleAyuda.com

AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X