Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator or script to batch convert pages to pdf files.

Hi,


I am trying to use this script Batch convert .pages to .pdf - Apple Community on Monterey Mac m1 and it is not working.

(*
	Copy/paste into Script Editor, and save as Text (e.g. pages2PDF.applescript). Then,
	option+Save As… and save as Application to the Desktop (pages2PDF.app). Drag and
	drop one or multiple Pages documents or a folder containing Pages documents onto
	the application, and the PDF will be written to the same location as the original.
	
	Reference: https://discussions.apple.com/thread/7915966?answerId=31605574022#31605574022
	
	Version:2.0, modified to fix hosting site command concatenation
	Tested: macOS 11.2.3, Pages v10.3.9
	VikingOSX, 2021-03-18, Apple Support Communities, No warranties expressed/implied.

*)

use scripting additions
property pages_kind : {"Pages Publication", "Pages Document"}


on open dropped_items
	
	repeat with anItem in dropped_items
		
		try
			tell application "Finder" to set akind to kind of anItem
			if akind contains "Folder" then
				tell application "Finder"
					set docList to (every item in entire contents of folder anItem whose kind is in pages_kind) as alias list
				end tell
				repeat with afile in docList
					export_file(afile)
				end repeat
			else if akind is in pages_kind then
				export_file(anItem)
			end if
		on error errmsg number errnbr
			my error_handler(errnbr, errmsg)
			tell application "Pages" to if it is running then quit
			return
		end try
	end repeatend open
return

on export_file(theFile)
	tell application "Finder" to set name_ext to name extension of theFile
	set exportDocument to text 1 thru ((offset of name_ext in (theFile as text)) - 1) of (theFile as text) & "pdf"
	-- Permissions error fix for Sierra < 10.12.4, and Pages v6, v6.0.5
	close access (open for access exportDocument)
	
	tell application "Pages"
		try
			set mydoc to open theFile
			with timeout of 1200 seconds
				if (version of it) ≥ "5.6" then
					set export_quality to (Best as constant)
					export mydoc to file exportDocument as PDF with properties {image quality:export_quality}
				else
					export mydoc to file exportDocument as PDF
				end if
			end timeout
			close mydoc saving no
		on error errmsg number errnbr
			my error_handler(errnbr, errmsg)
			tell application "Pages" to if it is running then quit
			return
		end try
	end tell
	
	tell application "Finder"
		if exists (file exportDocument as alias) is true then
			set extension hidden of (file exportDocument as alias) to false
		end if
	end tell	returnend export_file

on error_handler(nbr, msg)
	return display alert "[ " & nbr & " ] " & msg as critical giving up after 10end error_handler

Does anyone has an idea to fix this or have an automator ?


I have a lot of Pages files to convert to PDF any help is appreciated thanks !



MacBook Pro 13″, macOS 11.4

Posted on Jun 7, 2022 6:54 AM

Reply

Similar questions

2 replies

Jun 7, 2022 9:31 PM in response to Barney-15E

HI, thanks for your reply.


I have compiled and it is not showing any error. I can drop the files into the script but the screen blinks not even 1 second as if wanting to do something and then nothing happen.


I tried another script from VikingOSX, and it is reproducing an error he could not reproduce, saying export file completed and file = 0. It seems the problem is due to the language of the OS and needs to change a few words into my language but I have difficult time to pinpoint which words I should translate and the ones I can't.


Batch convert Pages files to PDF - Apple Community




Automator or script to batch convert pages to pdf files.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.