Batch convert to pdf
Thanks.
MacPro 2.66 24" LED Display, Mac OS X (10.6.6), 12 G RAM, MBP 17"/2.8 core 2 duo, 10.6.5, 8 G RAM, Canon 5D, 50D, G11
MacPro 2.66 24" LED Display, Mac OS X (10.6.6), 12 G RAM, MBP 17"/2.8 core 2 duo, 10.6.5, 8 G RAM, Canon 5D, 50D, G11
Why pay for a Pages export tool, when you can get one here for free that does the same thing?
I have written, and shared said tool with the Pages for Mac community multiple times — a drag & drop AppleScript solution that batch exports single, multiple, or folders of Pages documents to your choice of PDF, or Word (.doc/x) formats. It even gives you a choice of writing the exported documents to a separate output folder.
I will post it here again, if you request it (and you are running OS X 10.10 or later).
Click Compile, but not Run.
Drag and drop a single/multiple Pages '06 - '09, v5, v6 document(s), or folder containing them, onto the application icon on the desktop. You will be prompted to choose the export format, and then if you want the exported documents written to the original document location, or to a separate folder.
It is a necessary annoyance that the batch conversion process will open Pages for each document, and keep it on screen as long as it takes to export. When all exports are done, a dialog is presented with the processed file count. PDF documents will be exported Best quality if using Pages v5.6 or later.
-- pages_export.applescript -- -- Usage: Drag & Drop Pages document(s), and/or folder(s) containing them. -- Recursively processes folder contents, and exported files written to specified -- folder (default), or to original file location with new extension. -- Export supported and tested: PDF, docx, and doc. -- Export to USB stick tested successfully. -- To be saved as AppleScript Application -- Version: 2.0 -- Tested: OS X El Capitan 10.11.6, macOS Sierra 10.12.5 -- 3x faster on El Capitan with same version of AppleScript -- Require: OS X 10.10 or later. Pages v5.5.3 or later. Application will check. -- VikingOSX, 2017-06-30, Apple Support Communities property ca : current application property fmsg : "Choose or Create Export Folder:" property fdefault : (path to desktop) as alias property export_choices : {"PDF", "DOCX", "DOC"} property msg : "Choose Pages Export Format:" & return & "DOCX (default - return):" property exportFormat : "" property expFolder : "" property valid_kind : {"Pages Publication", "Pages document"} property fileCnt : (0 as integer) property app_icon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns" use framework "Foundation" use AppleScript version "2.4" -- Yosemite 10.10 or later use scripting additions on run -- only if the user double-clicks the application icon display alert "Drag and Drop Pages documents and/or folder(s) of Pages documents" & return & ¬ "onto the application icon. Make your export choice from the export type selection." quit end run on open dropped_items tell application "Finder" to set sys_version to version considering numeric strings if sys_version < "10.10" then display alert ¬ "You need OS X Yosemite 10.10 or later to run this script." giving up after 10 quit end if end considering tell application "Pages" to set aversion to version of it considering numeric strings if aversion < "5.5.3" then display alert "You need Pages v5.5.3 or later to run this script" giving up after 10 quit end if end considering try set choice to text returned of (display dialog ¬ "Exported files to separate folder (Y/N)?" default answer "Y") if {"Y", "y"} contains choice then repeat while true set expFolder to (choose folder with prompt fmsg default location fdefault ¬ without invisibles, multiple selections allowed and showing package contents) if not expFolder is equal to fdefault then exit repeat end repeat end if set exportFormat to (choose from list export_choices with prompt msg ¬ default items {"DOCX"} multiple selections allowed false ¬ with empty selection allowed) if exportFormat is false then error number -128 -- user cancelled set exportFormat to lowercase (item 1 of exportFormat) on error errmsg number errnbr my error_handler("dropped items prep", errnbr, errmsg) quit end try repeat with anItem in the dropped_items try tell application "Finder" set akind to kind of anItem if akind is equal to "Folder" then set docList to (every item in entire contents of folder anItem ¬ whose kind is in valid_kind) as alias list repeat with afile in docList my export_file(afile) end repeat else if akind is in valid_kind then my export_file(anItem) end if end tell on error errmsg number errnbr set errval to "Dropped Items repeat - " & (anItem as text) my error_handler(errval, errnbr, errmsg) quit end try end repeat display dialog "Export Complete." & return & tab & " Files exported to " & ¬ exportFormat & " : " & (fileCnt as text) ¬ buttons {"Done"} default button "Done" with title "Pages Export Facility" with icon POSIX file app_icon as alias quit end open on export_file(theFile) try set exportDocument to new_extension(theFile, exportFormat, 0) as POSIX file if not expFolder = "" then -- because Finder can't get name of non-existent file at this point set basename to new_extension(theFile, exportFormat, 1) as text set exportDocument to (expFolder & basename) as text end if -- necessary to avoid export write permissions issues on Sierra close access (open for access exportDocument) on error errmsg number errnbr my error_handler("Export file exportDocument", errnbr, errmsg) quit end try tell application "Pages" try set myDoc to open theFile with timeout of 1800 seconds if {"docx", "doc"} contains exportFormat then export myDoc to file exportDocument as Microsoft Word else if (version of it) ≥ "5.6" then export myDoc to file exportDocument as PDF with properties {image quality:Best} else export myDoc to file exportDocument as PDF end if end timeout set fileCnt to (fileCnt + 1) as integer close myDoc saving no on error errmsg number errnbr my error_handler("Export file", errnbr, errmsg) quit end try end tell -- force extension visible on all exported documents try -- occasionally get -8058 error which is caused by trying to duplicate -- a mounted drive with the Finder -- which is nonsense here, so ignore. tell application "Finder" if exists (item exportDocument as alias) then set extension hidden of (item exportDocument as alias) to false end if end tell on error errmsg number errnbr if not errnbr = -8058 then set errval to "Finder ext hidden: " & exportDocument as text my error_handler(errval, errnbr, errmsg) quit end if end try return end export_file on new_extension(afile, ext, name_flag) -- handler has two roles based on name_flag value -- 0) return full path of original filename with replacement extension -- 1) return just the basename without path set fullPath to ca's NSString's alloc()'s initWithString:(POSIX path of afile) set newfile to (fullPath's stringByDeletingPathExtension)'s stringByAppendingPathExtension:ext if name_flag = 1 then return (newfile's lastPathComponent()) as text end if return newfile as text end new_extension on lowercase (astr) -- make passed string all lowercase return ((ca's NSString's alloc()'s initWithString:astr)'s lowercaseString()) as text end lowercase on error_handler(nbr, msg, handler_name) return display alert handler_name & ": " & "[ " & nbr & " ] " & msg as critical giving up after 10 end error_handler on quit {} -- perform these cleanup items, and then really quit tell application "Pages" to if it is running then quit set fileCnt to (0 as integer) set exportFormat to "" set expFolder to "" continue quit end quit
Sorry I'm a newbie here.
Can someone enlighten me "step by step" what to do with the script? 😊
I tried to copy and paste into apple script editor but nothing seems to happen after that
You double click on the script and it will open in the script editor. Then you will be able to get instruction both in french and english.
Thanks for the reply!
Do you mean copy and paste the scripts into script editor? I saved it and double clicked the script file and the script editor re-opened.
I was asking about how to use the script to batch convert Pages files into pdfs. I know KOENIG Yvan shared with us some scripts, but what do I do after entering it into the script editor?
You save them as scripts to run from the Script Editor, or in Automator, or a Scripts menu on the menubar, or as an Application to run when you double click on it, or as a Droplet to drop files onto, that then get acted on by the script. You can even run them from Terminal.
Peter
I found iWorkConverter, a commercial app can batch conversion pages to docx and pdf.
Batch convert to pdf