Scripting InDesign to Create PDF files

Hi James…
Still working on figuring out the quark differences…but since your INDD works OK, I can still sue that one…
I do have a question though…If I wanted the pdf to be made on my desktop … just easier as I delete these once I send them and the INDD could come from anywhere, I would like it to point to the desktop and save there? Is that possible or does it have to save the PDF in the same location as the INDD? I was playing with your code trying to mess with the filepath variable…but, couldn’t get it? I know…I know…first I messed with the crops marks …and now this…how do you put up with me :wink:
thanks!
babs

Hi Monkeyhumper…
That sounds great…except…when I went to try change the preference, I don’t have InDesign as an option in that Convert to PDF category list. I didn’t see anyway to add the InDesign Application to that list. How did you get InDesign to show up?? I looked everywhere, but, couldn’t find it…
thanks!!!
Barbara

Change this

if (kind of theFile starts with "InDesign") then -- Process as InDesign
	set {filePath, fileName} to {container, name} of theFile
	my createInDesignPDF(theFile, filePath as Unicode text, (text 1 thru -6 of fileName))
else -- Process as Quark
	my createQuarkPDF(theFile)
end if

To this

if (kind of theFile starts with "InDesign") then -- Process as InDesign
	set fileName to name of theFile
	my createInDesignPDF(theFile, path to desktop as Unicode text, (text 1 thru -6 of fileName))
else -- Process as Quark
	my createQuarkPDF(theFile)
end if

And that should do the trick :smiley:

Well I managed to track down a copy of Quark within my organization and get it installed. So here is a working PDF Maker script that will handle either a Quark Document or InDesign Document dropped.

Tested on QuarkXPress 6.5.2 & InDesign CS3

on open fileList
	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 {filePath, fileName} to {container, name} of theFile
				my createInDesignPDF(theFile, filePath as Unicode text, (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 "[Smallest File Size]"
		set newProps to {view PDF:true, page range:"2", crop marks:true, bleed marks:true, color bars:true, registration marks:true} & 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

hi James…
worked beautifully :wink:
I’m just messing with it now to force the pdfs to the desktop…
totally awesome :wink:
Glad you were able to track down the software. I am using quark 7 but it worked fine on that one too :wink:
thanks!
babs

Hi Monkeyjumper…
Interesting, I came home where I am using acrobat 8 and found the Indesign option in the convert PDF in here…Either it wasn’t in my work version, which is 7.0, or somehow it was not installed to allow that at my company.
Things like that happen…
It worked…thanks!
barbara

This will save to the desktop for InDesign, I’ll look into doing it with quark. (Are you on Tiger or Leopard? … please say Leopard =))

on open fileList
	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, path to desktop as Unicode text, (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 "[Smallest File Size]"
		set newProps to {view PDF:true, page range:"2", crop marks:true, bleed marks:true, color bars:true, registration marks:true} & 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

hi james…
Don’t kill me … I run Leopard at home…but tiger at work ;-(
barbara

hey james…
the script worked great at home with Leopard running…
I will test it at work tomorow on my tiger…machine…
we will see :wink: :slight_smile: :slight_smile:

thanks
babs

Well my posted script should work fine on both Tiger and Leopard, but the issue will come if we try and make Quark go to the Desktop. The reason for that is because we are using GUI scripting and I’m pretty positive that Quark uses the OS File Dialog for saving like most applications do. Since this, unlike the Quark dialogs, is dependent on the OS the execution will vary from Tiger to Leopard and I don’t have a Tiger machine with Quark to test on.

Hi James…
soooooo close…
tried it at my office station running Tiger and got the following message for the InDesign one…quark is fine…
It actually makes the PDF and opens it in acrobat from InDesign but can’t seem to save it to the desktop.
Here is the message:

Can’t make <> of application “Finder” into type constant

What do you think???
thanks
babs

Thankfully the InDesign on Tiger is something I can test so I will take a look at it once I get into the office this morning.

Thanks James!:D:D

Barbara, this should work now on Tiger or Leopard.

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 "[Smallest File Size]"
		set newProps to {view PDF:true, page range:"2", crop marks:true, bleed marks:true, color bars:true, registration marks:true} & 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

hi James…
I’m back in Jersey already for the day…working from here on Leopard…
Will be back in the city tomorrow to check it out on Tiger.
Will keep you posted!!!
thanks for all the help…
Was studying your scripts on the bus today…very helpful and actually starting to sink in ;-0
catch up tomorrow!
thanks
babs

hi James…
You the man :lol::lol::lol:
worked like a charm…
thanks for your tiresome work on this :slight_smile:
babs

Hi barbara glad I could be of help!