Saving my PDFs to a specific folder

I have a script (see below) that takes a InDesign or Quark file and creates a PDF file using a specified setting, and currently saves the PDF to the original location that the file originated from. How do you specify a specific destination folder rather than the original location?

on open fileList
set deskPath to path to desktop as Unicode text
tell application “Finder”
repeat with i from 1 to count of items of fileList
set theFile to item i of fileList
if not ((kind of theFile starts with “Quark”) or (kind of theFile starts with “InDesign”)) then
display dialog “This file is not an InDesign or Quark document!” buttons “Skipping” default button “Skipping” with icon 0 giving up after 6
return
end if
–Determine whether to use InDesign subroutines or Quark subroutines
if (kind of theFile starts with “InDesign”) then – Process as InDesign
set fileName to name of theFile
my createInDesignPDF(theFile, deskPath, (text 1 thru -6 of fileName))
else – Process as Quark
my createQuarkPDF(theFile)
end if
end repeat
end tell
end open

on createInDesignPDF(theFile, savePath, docName)
tell application “Adobe InDesign CS3”
open theFile
set theProps to properties of PDF export preset “[C2Media_PDF]”
set newProps to {view PDF:true, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
set oldProps to properties of PDF export preferences
set properties of PDF export preferences to newProps
export front document format PDF type to (savePath & docName & “.pdf”) without showing options
set properties of PDF export preferences to oldProps
close front document saving no
end tell
end createInDesignPDF

on createQuarkPDF(theFile)
tell application “QuarkXPress”
open theFile
activate application
end tell
tell application “System Events”
tell process “QuarkXPress”
click menu item “Layout as PDF…” of menu 1 of menu item “Export” of menu 1 of menu bar item “File” of menu bar 1
delay 5
click button “Save” of window “Export as PDF”
delay 5
end tell
end tell
tell application “QuarkXPress”
activate
close front document saving no
end tell
end createQuarkPDF

thanks!!!
barbara

Barbara, from the InDesign part of your script this should not be a problem as you are using a scriptable variable (savePath & docName & “.pdf”) to export the file in to. From the Quark part of your script you resort to GUI scripting the export. Presumably you are using a version that has no class for this function? The default behavior I think will be to desktop or last exported location if it was not the desktop. Therefore your script could be prone to failure by user changes you will have to bare this in mind. You could leave it as is if this is working for you and just have finder move the PDF once its created. You may also require a file size check to confirm the PDF has finished being created before you try moving it. Where are they being moved to?

Hi Barbara,

For the Indesign part you could use this:

on open fileList
	set destpath to (choose folder) as string
	tell application "Finder"
		repeat with i from 1 to count of items of fileList
			set theFile to item i of fileList
			if not ((kind of theFile starts with "Quark") or (kind of theFile starts with "InDesign")) then
				display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
				return
			end if
			--Determine whether to use InDesign subroutines or Quark subroutines
			if (kind of theFile starts with "InDesign") then -- Process as InDesign
				set fileName to name of theFile
				my createInDesignPDF(theFile, destpath, (text 1 thru -6 of fileName))
			else -- Process as Quark
				my createQuarkPDF(theFile)
			end if
		end repeat
	end tell
end open


on createInDesignPDF(theFile, destpath, docName)
	tell application "Adobe InDesign CS3"
		open theFile
		set theProps to properties of PDF export preset "[C2Media_PDF]"
		set newProps to {view PDF:true, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
		set oldProps to properties of PDF export preferences
		set properties of PDF export preferences to newProps
		export front document format PDF type to (destpath & docName & ".pdf") without showing options
		set properties of PDF export preferences to oldProps
		close front document saving no
	end tell
end createInDesignPDF

I guess there is an export PDf script for Quark on this Forum depending on the version you use.
Yoy could use parts of it for your script.
If you need any help, just let me know.

–Peter–

thanks Peter and Mark…
I am on the road teaching all day today and tomorrow and will try these again over the weekend…
I appreciate the help greatly!!
be back soon :wink:
babs

Scripting Quark to make a PDF takes two paths, if you want to avoid GUI scripting. First the print setup record properties can be scripted to set how the PDF will be set (page size, bleed, registration marks, etc.) which can then be printed to a postscript file with the print command. The second step is to script Acrobat to turn that postscript file into a PDF (and set other properties of distilling if needed). InDesign has all the Acrobat “hooks” in it’s innards and both can be scripted, but Quark’s only connection to Acrobat is via the GUI.

Hello Peter,
This part you added worked for putting the PDF in a chosen folder for InDesign Document, but as you indicated it still won’t work for quark files… I will review the forum, as you suggested to see if I can find anyway to now force the quark PDF’s to choose a folder to save to.
Thanks for helping me get there…one more thing to accomplish and then I think it will work great for either program.
barbara

on open fileList
	set destpath to (choose folder) as string
	tell application "Finder"
		repeat with i from 1 to count of items of fileList
			set theFile to item i of fileList
			if not ((kind of theFile starts with "Quark") or (kind of theFile starts with "InDesign")) then
				display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
				return
			end if
			--Determine whether to use InDesign subroutines or Quark subroutines
			if (kind of theFile starts with "InDesign") then -- Process as InDesign
				set fileName to name of theFile
				my createInDesignPDF(theFile, destpath, (text 1 thru -6 of fileName))
			else -- Process as Quark
				my createQuarkPDF(theFile)
			end if
		end repeat
	end tell
end open


on createInDesignPDF(theFile, destpath, docName)
	tell application "Adobe InDesign CS3"
		open theFile
		set theProps to properties of PDF export preset "[C2Media_PDF]"
		set newProps to {view PDF:true, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
		set oldProps to properties of PDF export preferences
		set properties of PDF export preferences to newProps
		export front document format PDF type to (destpath & docName & ".pdf") without showing options
		set properties of PDF export preferences to oldProps
		close front document saving no
	end tell
end createInDesignPDF

one other thing…
on a few quark files, when I drag them onto the script, it kicks that display dialog message that says :

	display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6

the problem is, they are quark files…do you know what might cause that???

thanks
barb

Might be that the kind and name properties of the file are relying on the Finder. You can also use Standard Additions to get ‘info for’ the file, which will have it’s name and kind. Using the Finder to identify files can lead to problems.

Either that or the file is not recognized at all as a Quark document and you’ll have to trust file extensions (which are either missing or incorrect) or look at the default application or the type identifier.

set testFile to (choose file)
kind of (info for testFile) starts with "Quark"
--kind of (info for testFile) is "QuarkXPress Project File"
--type identifier of (info for testFile) is "dyn.agk8zuycwmk"
--default application of (info for testFile) is alias "Macintosh HD:Applications:QuarkXPress 7.2:QuarkXPress.app:"

I went thru your script and borrowed some, streamlined others, since I’ll eventually be making scripts to do this sort of thing on a “server” with drop folders or a web interface that allows access to our department art as PDFs. I’ve just now gone from OS8.5 into the beginnings of a modern workflow and haven’t flushed out all the bugs, but this seems to work. Thot I’d share and make note why I changed what I did.

on open fileList
	set destpath to (choose folder) as string
	repeat with i from 1 to count of items of fileList
		set theFile to item i of fileList
		set fileInfo to (info for theFile)
		set fileName to name of fileInfo
		--Determine whether to use InDesign subroutines or Quark subroutines
		if (kind of fileInfo starts with "InDesign") then -- Process as InDesign
			my createInDesignPDF(theFile, destpath, (text 1 thru -6 of fileName))
		else if (kind of fileInfo starts with "Quark") then -- Process as Quark
			my createQuarkPDF(theFile, destpath, (text 1 thru -6 of fileName))
		else
			display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 6
			--return will exit script and not process other files in repeat, omiting 'return' will skip only those that are neither QXP or ID
		end if
	end repeat
end open


on createInDesignPDF(theFile, destpath, docName)
	tell application "Adobe InDesign CS3"
		open theFile
		set theProps to properties of PDF export preset "[C2Media_PDF]"
		set newProps to {view PDF:true, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps
		set oldProps to properties of PDF export preferences
		set properties of PDF export preferences to newProps
		export front document format PDF type to (destpath & docName & ".pdf") without showing options
		set properties of PDF export preferences to oldProps
		close front document saving no
	end tell
end createInDesignPDF

on createQuarkPDF(theFile, destpath, docName)
	set tempPSfile to (path to temporary items as string) & "tempPS.ps"
	tell application "QuarkXPress"
		open theFile
		set theDoc to object reference of document 1
		--print setup record can be checked for settings you may need to specify
		--return print setup of theDoc
		(*{class:print setup record, object reference:print setup record 0 of document "Medical Catalog" of application "QuarkXPress", output setup:"Process SWOP", bleed:"0p", absolute overlap:true, auto tile overlap:"18p", back to front:false, collate:false, data format:binary data, fit in area:true, flip horizontal:false, flip vertical:false, full res rotated objects:false, halftone screen:"106", include blank pages:false, invert image:false, orientation:portrait, page gap:"0p", page position:center position, page sequence:all pages, paper offset:"0p", paper size:"Letter", paper size list:{"A4", "A5", "A6", "B5 (JIS)", "Legal", "Letter", "Executive", "5.5x8.5", "8x13", "8.25x13", "8.5x13", "Com10 Env.", "Mon. Env.", "C6 Env.", "C5 Env.", "DL Env.", "16K", "Custom"}, paper width:"51p", paper height:"p.015", print quality:normal, print spreads:false, print thumbnails:false, printer type:"Generic B&W", printer type list:{"Generic B&W", "Generic Color", "Generic Imagesetter", "Generic PDF", "AdobePDF 8.0"}, reduce or enlarge:"94%", registration marks:off, registration marks offset:"6 pt", resolution:600, separation:false, tiling:off} *)
		tell print setup of theDoc
			set previousPaperSize to paper size --we'll need this later
			
			--may want to check for the printer type name of AdobePDF on your system
			set checkPrinterType to printer type list
			if checkPrinterType does not contain "AdobePDF 8.0" then ¬
				error "Distiller not installed!"
			
			--if that works then free to set all needed properties of the PDF printout
			--can also be done with custom output setup, ie;
			--ignor print setup record and create an output setup, then
			--set output setup to "postscript to PDF Settings"
			set printer type to "AdobePDF 8.0"
			set paper size to previousPaperSize --default for AdobePDF page is "Screen" so it must be set to original page/paper size
			set fit in area to false
			set reduce or enlarge to "100%"
			set registration marks to off
			--print to file (temporary postscript file)
			print theDoc PostScript file tempPSfile
			close theDoc saving no
		end tell
	end tell
	--then create the PDF
	my distillPSfile(tempPSfile, destpath, docName)
end createQuarkPDF


on distillPSfile(tempPSfile, destpath, docName)
	set pdfPath to destpath & docName & ".pdf" as string
	tell application "Adobe Acrobat Professional"
		open tempPSfile with invisible
		save document 1 to pdfPath
		close document 1
	end tell
	--this method has Acrobat Pro use Distiller to convert file
	--so it launches in addition to Acrobat Pro when converting
	
	--I think it can also be scripted with Distiller directly and
	--without using Acrobat Pro, but I've not tried to flush it out
end distillPSfile

Well, here is what I can figure out so far, and it may be OK…

I think the reason it isn’t seeing them as quark files, is because they are on a read only server. If I drag the files off the server and put them anywhere else, it works fine. It is just for me to make back up PDFs so I can drag them off, and run my script and get rid of them after the fact.

What I can do as far as choosing a folder goes, is drag the folder to the sidebar for easy access, and just make that decision once during the save as using the delay in the script. It gives me plenty of time to choose it…then I can walk away and the rest will follow.
I don’t know how to prevent the message on the read only server, and I really don’t want to do anything harmful there, so this may have to do.

I also just tried your other script which although gives me the option to choose a folder, it is trying to print rather than make a PDF…but I will try to take some of yours with my PDF part and see if I have more luck.

I like that little script that shows the file type as quark…pretty cool :wink:

Worst case scenario, I do my little work around :wink:
it still beats making them one by one…

thanks so much for all your help…

barbara

Ya, I had similar situation with a read/write SnapOS NAS which could offer a public folder to which my desktop has attached a folder action for unattended and unseen conversions of various types. Making sure the script processed only certain types of files became problematic, and I resorted to two checks, first for macintosh file types and things, then for allowed “dot-three” extensions in the file names that aren’t displayed on the Windows users save as or files copied to the folder. Even with that it’s a gamble that something gets in that isn’t what is expected, which makes it hard to process files unattended.

If you’re the only one dropping files onto the script, it’s a safe bet you won’t try to open a Powerpoint file with Quark or something, but then I always like to have an error trap for the occasions when I do accidentally drop the wrong file onto a script.

You can avoid the message by not displaying the dialog to report an error, and instead write the file name to a text file on your desktop. Or ignore the file type issue with Quark and just keep fingers crossed. Has an InDesign file ever failed to be recognized as such? Gotta be able to tell the difference, otherwise you’ll need two droplets to process both kinds of files regardless of whether or not the script recognizes the kind of any one or more of the files dropped onto it.

Ya, it’s a shame that there’s no access (via applescript) to the PDF output setup dialog and profiles with Quark, but also understandable. That dialog and process is not native to Quark, it’s only an Acrobat Pro resource that is activated by Quark. You might continue hitting a wall when scripting it, even the GUI, unless you can go from the Quark document properties right to the Distiller/Acrobat properties; only way I know how to do that with applescript is via postscript output from Quark.

If I don’t know why a script does what it does, I ponder. If I don’t know what a script is doing, I find out! :wink:

You’re welcome, and thank you for the InDesign part. I’ve never scripted that one and have few of that type of file to worry about, but the less I have to experiment the better. I’ll probably revisit the whole issue once I get past all the other art projects in the way of rebuilding the whole department system.

I was thinking of trying to get rid of the trap, knowing I would never pull anything but a quark file…so I think I will try that.

I didn’t try an Indesign file yet off that server, but I certainly will. I am not there at the moment and won’t be till Tuesday…darn, I want to play with it :wink:

I know, InDesign seems to make this much easier…it seems like a simple request…

Glad you could use something here, and thanks for your help… Once I am back on Tuesday, I will try some more here… Good Luck with putting your system together for your department!!!

I think it is, too. I just can’t decide whether to ask Adobe to provide Quark with that kind of Acrobat-ability or to ask Quark to make Adobe provide it for XPress. InDesign has it made, since they both are from Adobe sharing Acrobat abilities with InDesign is simple. At least, not as legally complicated.

Far as I’m concerned they both take too many liberties with the postscript language, even if one of them did happen to invent it. :wink: