1

I have been tasked with converting lots of .numbers files to .pdf. Having exported manually did not satisfy me, obviously, so I dug around online and found an automator script (below). It obviously is easier and quicker than manual export, but I would love to just select a folder and let the script do the rest for each and every .numbers file in the folder. Tried to tweak the script a bit acc to what I found online, but was not able to fuse it together, can anybody advise, please?


tell application "Finder"
    set theFilesFolder to (folder of theFile) as text
end tell

tell application "Numbers"
    set theDoc to open theFile
    
    set theDocName to name of theDoc
    
    --I'm assuming that the file name always ends with ".numbers"
    set theName to (characters 1 thru -7 of theDocName) as text
    
    export theDoc as PDF to file ((theFilesFolder & theName & ".pdf") as text)
    
    close theDoc
    
end tell

1 Answer 1

1

Iterate Items / … of Chosen Folder

You can use a snippet provided by Script Editor:

  1. Launch Script Editor.app
  2. Create a new script
  3. Control-Click (or right-click) within the new script's editor
  4. Select Iterate Items > Images of Chosen Folder

Script Editor snippets

This will paste in a snippet to choose a folder, then perform a task on matching files.

I have modified this snippet and inserted your code below:

set this_folder to (choose folder with prompt "Pick the folder containing the files to process:") as string
tell application "System Events"
    set these_files to every file of folder this_folder whose name does not start with "." and name extension is "numbers"
end tell
repeat with i from 1 to the count of these_files
    set this_file to (item i of these_files as alias)
    
    tell application "Numbers"
        set theDoc to open this_file
    
        set theDocName to name of theDoc
    
        --I'm assuming that the file name always ends with ".numbers"
        set theName to (characters 1 thru -7 of theDocName) as text
    
        export theDoc as PDF to file ((theFilesFolder & theName & ".pdf") as text)
    
        close theDoc
    
    end tell
    
end repeat
5
  • Hi, thanks for replying. When I inserted your script, I got an error, saying „«class cpkg» "Macintosh HD:Users:jakubkilian:Library:Mobile Documents:com~apple~Numbers:Documents:Revize:Applemix (kopie):REVZ_S_A037.numbers:" of application "System Events"“ cannot be set to type „alias“.". When I tried to build as you suggested, the script does not produce an error, but nothing happens. Can you help, please? Commented Oct 24, 2022 at 12:49
  • What happens if you try a new script running only the snippet inserted from the context menu? Does that part work? If not, what version of macOS are you running? Commented Oct 24, 2022 at 13:10
  • Well I have tried to insert a new snippet and modify it so “numbers” was within allowed file extensions, but it led to no actions, the script stopped without an error but no files were created. I’m on the last version of Big Sur. Commented Oct 24, 2022 at 13:16
  • Please can you update your question with the latest script. Commented Oct 24, 2022 at 13:18
  • Really wanted to but have closed the script before and then was not able to reach the same "no error but no files" result as before :-D anyway, it seems to me that the main problem is here set this_file to (item i of these_files as alias), not sure why though. Can it be because I am "only" at 11.7 Big Sur? Commented Oct 24, 2022 at 17:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.