最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

applescript - Export all .pages files from one folder to pdf in another folder - Stack Overflow

programmeradmin2浏览0评论

Here is my script

set docsFolder to choose folder with prompt "Select the folder containing Pages documents:"
set pdfFolder to choose folder with prompt "Select the folder to save PDFs:"

tell application "Finder"
    set pagesFiles to every file of docsFolder whose name extension is "pages"
end tell

repeat with pagesFile in pagesFiles
    set docPath to pagesFile as alias
    set docName to name of pagesFile
    set baseName to text 1 thru ((length of docName) - 6) of docName -- Retire ".pages"
    set pdfPath to ((pdfFolder as text) & baseName & ".pdf") as text -- Force un chemin valide

    tell application "Pages"
        open docPath
        delay 1 -- Laisser le temps au document de s'ouvrir
        tell front document
            export to file pdfPath as PDF
            close saving no
        end tell
    end tell
end repeat

and the error is: Erreur dans Pages : Forme de clé invalide.

What's wrong ??? thanks for your help

I'm expecting pages to export to pdf but I have this message.

Here is my script

set docsFolder to choose folder with prompt "Select the folder containing Pages documents:"
set pdfFolder to choose folder with prompt "Select the folder to save PDFs:"

tell application "Finder"
    set pagesFiles to every file of docsFolder whose name extension is "pages"
end tell

repeat with pagesFile in pagesFiles
    set docPath to pagesFile as alias
    set docName to name of pagesFile
    set baseName to text 1 thru ((length of docName) - 6) of docName -- Retire ".pages"
    set pdfPath to ((pdfFolder as text) & baseName & ".pdf") as text -- Force un chemin valide

    tell application "Pages"
        open docPath
        delay 1 -- Laisser le temps au document de s'ouvrir
        tell front document
            export to file pdfPath as PDF
            close saving no
        end tell
    end tell
end repeat

and the error is: Erreur dans Pages : Forme de clé invalide.

What's wrong ??? thanks for your help

I'm expecting pages to export to pdf but I have this message.

Share Improve this question asked Feb 15 at 13:12 Jean-François MARQUISJean-François MARQUIS 133 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

What happens if you change your pages tell block to this:

    tell application "Pages"
        activate
        open docPath
        delay 1 -- Laisser le temps au document de s'ouvrir
        export front document to file pdfPath as PDF
        close front document saving no
    end tell

The problem is likely that you had the export command inside a tell front document block, which means that it was adding an unwanted specification to your export… something like this:

export document 1 to file "MacHD:Users:whomever:Desktop:destination:docco.pdf" of document 1 as PDF

You don't want that of document 1 in there.

I think that the invalid key form of the error message suggests that the file specifier is not properly formed.

If you look at the log you can see how the export line changes depending on the tell block.

Alternative approach

If you remove the word file from the export command line, then the export should not be affected by this issue. The reason being that if you exclude that word then you are working with a string rather than a file specifier.

In effect:

"MacHD:Users:whomever:Desktop:destination:docco.pdf" instead of
file "MacHD:Users:whomever:Desktop:destination:docco.pdf"

So either fo these should work:

without front document block

    tell application "Pages"
        activate
        open docPath
        delay 1 -- Laisser le temps au document de s'ouvrir
        export front document to pdfPath as PDF
        close front document saving no
    end tell

with front document block

    tell application "Pages"
        open docPath
        delay 1 -- Laisser le temps au document de s'ouvrir
        tell front document
            export to pdfPath as PDF
            close saving no
        end tell
    end tell

Of course, apple changes stuff with each OS version so maybe things have changed since Sierra but hopefully this helps.

发布评论

评论列表(0)

  1. 暂无评论