Do a file search and loop through results... Batch Quark files to PDF

Hi everyone

I’m a network admin for a small publishing business, and the guys who use the Macs have a particular problem I need to solve.
Batch converting up to 100 Quark 6.5 files to PDF files, and I’m a complete newbie to AppleScript.
On a PC this could be done very easily but that’s not an option with this since we need the PDF to look exactly like the source Quark file… converting the Quark files to PC Quark, then having the fonts substituted for PC equivalents causes changes in the spacings etc.

The guys in the studio are using a variety of OSX versions, some Panther, some Tiger.
I believe the OSX Automator only appeared with Tiger, though I am probably wrong as I’m not in the world of Macs.

But for this task, we can just use the same machine every time so if it can only be done on Tiger then we’ll just always run it on that particular Mac.

Each issue of the magazine lives in a separate folder on our NAS.
Then each page or spread is in it’s own sub-folder along with the original word/text docs and all the images for that page/spread.

I’m guessing it’ll be difficult to access the NAS through AppleScript, so if necessary I can copy the issue folder from the NAS onto the OSX desktop. Then the script just runs through the local copy.

Here was my theory of how the script would run…

  • Search through the magazine issue folder and return all Quark files from any subfolders.
  • Loop through each Quark document in the search results, opening it and running a particular menu/shortcut or menu option, close the Quark document

Right now I’m only concerned about part 1.
Once I’ve got that working I will worry about how Quark actually outputs the PDF, there are a few different options available for that.
So for the time being, all I want to achieve is to get Quark to open then close that Quark document… then move on to the next file in the results.

Is there a way to automate a search, return all files of a particular document type, then loop through each one of the search results?

With a PC this bit is easy since all documents of a certain type, have the same file extension.
But the quark files created by the Macs have no such file extension… although it can be enabled if necessary… but I’d like to find a way of doing it without relying on our Mac designers remembering to add the file extension.

Does anyone have any AppleScript snippets that I can look through on how to script a file search?
Is there a reference of all the built in OSX AppleScript actions / functions?

I’ve just started messing around with the AppleScript Script Editor… I guess that’s the right place to start writing the script?

Here’s what I’ve managed to get so far…

-- SPECIFY FOLDER TO START THE SEARCH
set SourceFolder to (choose folder with prompt "Select the folder containing the Quark documents") as text

-- SPECIFY FOLDER FOR PDF OUTPUT
set OutputFolder to (choose folder with prompt "Select the folder where the PDFs will be saved") as text

-- DO SEARCH FOR ALL QUARK DOCS UNDER SourceFolder
-- LOOP THROUGH EACH SEARCH RESULT
-- MAYBE A WAY TO GET ALL THE SUB-FOLDER NAME AND FILE NAMES INTO A BIG ARRAY

tell application "QuarkXPress Passport"
	activate
	open
	-- OUTPUT AS PDF STUFF IN HERE
	close

end tell

Here’s the specs of the system I’m using to develop this script:
AppleScript 1.10.7
Script Editor 2.1.1 (81)
OSX 10.4.10
Dual 2 GHz PowerPC G5, 1.5GB DDR2 SDRAM
And the version of Quark is 6.5 Passport

Thanks
Ben

Hi

This should get you started!!

tell application "Finder"
	activate
	set t to every file of entire contents of (choose folder) whose file type is "XPRJ"
	repeat with i in t
		open t
		delay 2
		tell application "QuarkXPress" to close document 1
	end repeat
end tell

“XPRJ” is the file type that the mac uses for quark docs even though you don’t have show extensions switched on!!
every file as one of these properties.

Theres a few ways to get pdf’s via applescript in quark in my experience none are very good!
i go down the route of saving as a postscript and pointing it towards a distiller watched folder!!
the save layout as pdf option can only be scripted via the GUI which can be flakey and unreliable at times!!

do a search across this forum the quark pdf issue as cropped up a lot!! i’m sure you’ll find what you want!!

Thanks for your quick reply.

However when I paste your script example and try to save it, I get the following error:

Syntax Error
Expected end of line, etc. but found property.

… With the word ‘contents’ in the 3rd line highlighted in the script editor.
Is there a way to solve that?

With regards to your suggestion of saving the page as an EPS… I was thinking of exactly the same thing.
There’s an AppleScript included with Quark that can save each page as an EPS so I will try to edit that so I end up with a folder full of EPS files.
Then a Distiller watch folder is one option, but I may also try and script that bit as well.

Postscript is the better route no font embedding in the quark .eps distiller is also scriptable so no need for watched folders a scripted solution allows more flexibility.

Not sure what the prob with that is!
I’m running the exact same version of OSX etc.
Have you tried a restart sometimes that can cure minor ailments like this!!

When i said save as postscript and then distiller i meant via the print command in quarks applescript but i guess you could distill an “eps”

Hi guys
Thanks for the replies

Ok I restarted and that solved the save problem.

Then I tried running your script and it appeared to open all of the Quark files in one go.

So I made a few modifications, so this is now my complete script:

-- SPECIFY FOLDER TO START THE SEARCH
set SourceFolder to (choose folder with prompt "Select the folder containing the Quark documents") as text

-- SPECIFY FOLDER FOR PDF OUTPUT
set OutputFolder to (choose folder with prompt "Select the folder where the EPSs will be saved") as text

tell application "Finder"
	activate
	set t to every file of entire contents of SourceFolder whose file type is "XPRJ"
	repeat with i in t
		
		tell application "QuarkXPress Passport"
			activate
			open t use doc prefs yes remap fonts no do auto picture import no
			delay 2
			
			--print t Postscript file
			
			close t saving no
		end tell
		
	end repeat
end tell

I changed your example to add the tell application QuarkXPress Passport bit, which is more wordy and I think still a valid thing to do.
I’ve also used a variable called SourceFolder that’s declared at the start of the script which is the prompt to choose the search folder.

But when I run this script I get the following error in script editor:
AppleScript Error
Can’t get entire contents of
“DWStudio5:Users:benb:Desktop:ISSUE187
:”.

I think the path I’m setting might not be formatted right… it seems from the above error message that there’s a trailing colon… is that the problem?

Also I had a look through the AppleScript dictionary for QuarkXPress Passport and found the print function… note the commented out --print t Postscript file
I’m guessing that’s the way to output a Postscript, rather than an EPS.

I will deal with the scripting of Distiller further down the line, but looking through the AppleScript dictionary for Distiller it seems there’s a few ways to get this done.

Any ideas on the above error?

Try some thing like this to get you started

set Top_Folder to choose folder with prompt "Please choose your top level folder?" without invisibles

tell application "Finder"
	try
		set Quark_Files to (files of entire contents of Top_Folder whose file type is "XPRJ") as alias list
	on error
		set Quark_Files to (files of entire contents of Top_Folder whose file type is "XPRJ") as alias as list
	end try
end tell

repeat with This_File in Quark_Files
	tell application "QuarkXPress"
		activate
		open This_File use doc prefs yes remap fonts no do auto picture import no
		tell document 1
			display dialog "Do you stuff here!" giving up after 3
			close saving no
		end tell
	end tell
end repeat

Hi Mark67

Thanks, your script snippet works perfectly!
It cycles through all the Quark files, opening then closing them.

I have 2 quick questions though…

  1. When I use the Finder > Find… function to search for “QuarkXPress Project Files”, how do I find out what that equates to in the world of OSX file extensions?
    EG how can I find out that a QuarkXPress Project File is equal to the string XPRJ
    Is there a master registry / utility somewhere that has all the file type/extension mappings listed out?

  2. What’s the reason for the 2 different lines that start?
    set Quark_Files to (files of entire contents of Top_Folder whose file type is “XPRJ”)
    I notice there’s a slight difference towards the end of the line.

Why is that?

Now all I need to do is get Quark to print to postscript.

Thanks for all your help so far guys!

A quick and easy way to look up you file types is to point something like this at your documents. When you’ve looked at a few of these you will then be able to work out which is going to prove the best route for your script.

set This_File to choose file with prompt "Where is the file?"
tell application "Finder"
	-- each property this is not all of them!!!
	get modification date of file This_File
	get creation date of file This_File
	get file type of file This_File
	get name of file This_File
	get creator type of file This_File
	get name extension of file This_File
	get comment of file This_File
	get kind of file This_File
	-- or the lot
	get properties of file This_File
end tell

The reason for the on error with the slightly different words is there is a error when only 1 item is returned. I don’t know if this has been fixed.