QXP Print to PDF, choosing files or folders, single or multiple output

I finally am getting some time in my schedule to dedicate to AS again. Time to pick up shelved projects and complete them!

I have a project that I would like to try making more complex. I have a few scripts that do some of these functions separately. I’m printing QuarkXPress files to PDF. Sometimes just one file needs to be input, sometimes it’s a whole folder of folders of Quark files. I’d like to be able to allow the user to choose which mode to begin with. Another feature would allow the user to print a PDF of each page of a Quark file, or a single PDF of each. I’d also like to try to choose the output folder as well.

I worked on one recently for saving each page of a Quark file to EPS files, based on the source file’s name, with some help from the inmates. :slight_smile: I’m not sure how to incorporate this, but the naming function would be nice to have. Adding the EPS/PDF choice to the mix would add another level of simplicity for the user, allowing them to use one script that does more instead of lots of small ones.
http://bbs.macscripter.net/viewtopic.php?id=27754

This script could end up processing a great number of Quark files, so for the folders mode would need to process all Quark files inside of sub-folders as well.

Would running the Quark work in subroutines help speed things up? I’ll post more here on this one as I make progress, as long as my free time stays mine!


tell application "Finder"
	display dialog "Please choose between File(s) or a Folder." buttons {"File(s)", "Folder"}
	set modeChoice to result
	display dialog "Please choose between a PDF per page or per file." buttons {"Page", "File"}
	set modeChoice to result
	display dialog "Please choose an output folder, either the same as the Source or a new folder." buttons {"Source", "New"}
	set outputLocation to result
	if result is "Folder" then
		display dialog "Please choose the input folder."
		set inputFolders to choose folder with multiple selections allowed --do script quarkFolder
		set theFiles to files of folder inputFolders whose name extension is in {"qxd"} or kind contains "QuarkXPress" or file type is in {"XPRJ", "XPR3"} or creator type is in {"XPRJ", "XPR3"}
		repeat with oneFile in theFiles
			tell application "QuarkXPress"
				activate
				open (oneFile as alias) do auto picture import no use doc prefs yes remap fonts no
				tell front document
					--print to PDF. Choose one PDF or one per page, based on input file name. Save to same location as original. Process all Quark files in all sub-folders.
					close saving no
				end tell
			end tell
		end repeat
	else
		display dialog "Please choose the input file(s)."
		set inputFiles to choose file with multiple selections allowed --Limiting to Quark files would be good --do script quarkFiles
		set theFiles to files of file inputFiles whose name extension is in {"qxd"} or kind contains "QuarkXPress" or file type is in {"XPRJ", "XPR3"} or creator type is in {"XPRJ", "XPR3"}
		repeat with oneFile in theFiles
			tell application "QuarkXPress"
				activate
				open (oneFile as alias) do auto picture import no use doc prefs yes remap fonts no
				tell front document
					--print to PDF. Choose one PDF or one per page, based on input file name. Save to same location as original.
					close saving no
				end tell
			end tell
		end repeat
	end if
end tell

tell application "Finder"
	activate
	display dialog "Done"
end tell

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 3.0.4
Operating System: Mac OS X (10.4)

I’ve gone back and organized the steps a bit, setting my variables and trying to make sure it all makes sense to me. I think my variables are how they need to be, but I’m not sure how to address the actual processing of files. It seems like I would want to do it outside of the ‘tell Finder’ block. Would that speed up the process?


tell application "Finder"
	
	display dialog "Please choose between Files or a Folder." with title "QXP to PDF v1.8" buttons {"Files", "Folder"}
	set modeChoice to result
	
	display dialog "Please choose between a PDF per Page or per File." buttons {"Page", "File"}
	set outputChoice to result
	
	display dialog "Please choose an output folder, either the same as the Source or a New folder." buttons {"Source", "New"}
	set outputLocation to result
	
	if button returned of modeChoice is "Folder" then
		display dialog "Please choose the input folder."
		set inputFiles to choose folder with multiple selections allowed --need to process all files in all sub-folders
	end if
	
	if button returned of modeChoice is "Files" then
		display dialog "Please choose the input folder."
		set inputFiles to choose file with multiple selections allowed
	end if
	
	if button returned of outputLocation is "New" then
		set outputFolder to choose folder
	end if
	
	if button returned of outputLocation is "Source" then
		--same as original
	end if
	
	if button returned of outputChoice is "Page" then
		--output one PDF per page based on source file's name
	end if
	
	if button returned of outputChoice is "File" then
		--output one PDF per file based on source name
	end if
	
	repeat with oneFile in (inputFiles whose name extension is in {"qxd"} or kind contains "QuarkXPress" or file type is in {"XPRJ", "XPR3"} or creator type is in {"XPRJ", "XPR3"})
		tell application "QuarkXPress"
			activate
			open (oneFile as alias) do auto picture import no use doc prefs yes remap fonts no
			tell front document
				--print to PDF. Choose one PDF or one per page, based on input file name. Save to same location as original. Process all Quark files in all sub-folders.
				close saving no
			end tell
		end tell
	end repeat
	
end tell

tell application "Finder"
	activate
	display dialog "All files have been processed."
end tell

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 3.0.4
Operating System: Mac OS X (10.4)