Skip to content

Instantly share code, notes, and snippets.

@loop
Created October 15, 2015 19:33
Show Gist options
  • Save loop/7207134ed7ff7a288ee1 to your computer and use it in GitHub Desktop.
Save loop/7207134ed7ff7a288ee1 to your computer and use it in GitHub Desktop.
convert pages to pdf applescript
set theFolder to choose folder with prompt "Select folder with original pages files :"
--Do it
tell application "Finder"
set theNames to name of files of theFolder ¬
whose name extension is "pages"
end tell
-- How many files to export
set item_count to (get count of items in theNames)
--Get files and export them
repeat with i from 1 to item_count
set current_file to item i of theNames -- get a file
set lean_file to text 1 thru -7 of current_file & ".pdf" -- change the originalfile (.pages) to a .pdf name
set out_file to (theFolder as Unicode text) & (lean_file) -- get the fully qualified output name
set in_file to (theFolder as Unicode text) & (current_file) -- get the fully qualified input file name
tell application "Pages"
set mydoc to open file in_file -- open input file in Pages
export mydoc to file out_file as PDF --do the exporting
close mydoc saving no -- close the original file without saving
end tell
end repeat
display dialog "done" -- Job done
@jlyonsmith
Copy link

jlyonsmith commented Nov 25, 2016

You sir or madam are an AppleScript rock star. I tried but I wasn't able to get the export command to work to work. I wonder if it was the Unicode text conversion?

@yannbolliger
Copy link

yannbolliger commented Jun 5, 2020

This is awesome so many thanks. What made it for me was that, the theFolder returned from the prompt has the type alias.

With your help I succeeded in letting the script take a relative path from the command line:
https://gist.github.com/yannbolliger/a09cb714429b0dcf28d7d3256de8d993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment