You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

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

Batch convert .pages to .pdf

Hello there,


there is this great AppleScript for a drag & drop converter of .pages to .pdf

https://discussions.apple.com/thread/7915966?answerId=31605574022#31605574022

but the script editor says something like

"given", "into", "with", "without" or other parameter name expected, but end of line found.



Posted on Mar 18, 2021 12:11 PM

Reply

Similar questions

2 replies

Mar 18, 2021 1:46 PM in response to VikingOSX

I forgot to mention that on Catalina with its elevated security, it will pose the following dialogs the first time you drop a file on that saved application on your Desktop. Click on OK to both of these and you won't see them again. I named my saved application p2pdf.app, which is where it is getting that reference in the dialogs:





Then the script will launch Pages, open the Pages document, export it, and quit Pages. For multiple Pages documents, it will cycle through the preceding sequence for each file.


I doctored up the 2017 script to get it posted here, but I have a newer script that also reports in a completion dialog how many PDF exports occurred.

Mar 18, 2021 1:04 PM in response to ist4000

Four years ago, the hosting software had a tendency to compress AppleScript commands by removing white-space and thus causing the compile error you observed. That is caused by:


on opendropped_items


which was actually posted as:


on open dropped_items


And there are several other instances in that linked code example where this syntax compression has occurred and breaks the script. I have fixed the altered syntax issues, and it is now producing a PDF from a dropped Pages document.


Here you go:


(*
	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 repeat
end 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
	return
end export_file

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



Batch convert .pages to .pdf

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