Need Help InDesign Scripting - Export PDF - Upload On Save

my company is in the process of making a switch from MultiAd Creator Pro to Indesign.

i wrote a script for MultiAd that uploads a pdf file to select volume/folder when the user saves the doc.

so …the user saves the doc. and is then prompted yes/no save the “Send Proof”? if yes then… the script uploads a PDF to a select destination.

below is the Creator script

pproperty PDFPath : “PDFProofs:”

using terms from application “MultiAd Creator Pro”
on saved theDoc
set question to display dialog “Send Proof?” buttons {“Yes”, “No”} default button 2
set answer to button returned of question
if answer is “Yes” then
set fileName to name of theDoc
set destFolder to PDFPath

		--Trim off .crtr extension if it has one:
		if fileName ends with ".crtr" then
			set sd to AppleScript's text item delimiters
			set AppleScript's text item delimiters to {"."}
			set fileName to (text items 1 thru -2 of fileName) as text
			set AppleScript's text item delimiters to sd
		end if
		
		
		tell application "MultiAd Creator Pro"
			
			export PDF current spread of theDoc saving in (destFolder & fileName & ".pdf") print order user order export method composite output color space CMYK stand in resolution 300 black and white compression use zip color image compression use JPEG quality 80 with embed no base 14 fonts, use doc size, binary encoding and compress text and line art without print as spreads, crop marks, registration marks, color bars, document notes, plate information, text blocks only and presentation mode
		end tell
		
		tell application "Finder"
			activate
			tell application "MultiAd Creator Pro"
				activate
			end tell
		end tell
	end if
end saved

end using terms from

IMO the script is fairly straightforward but i am not sure how to convert it into a Indesign script that would work in the background??

plus i don’t know how to capture the “export PDF” information (i.e. the preset PDF criteria) from Indesign.

there is no way to record scripts from with Indesign?? like photoshop?

any help would be greatly appreciated. thank you in advance rick

hey Rick

try this, to kick things off

set _ExportPDF to (display dialog "Send Proof?" with icon caution buttons {"Cancel", "PDF"} default button 2)
tell application "Adobe InDesign CC 2015"
	if button returned of _ExportPDF is "PDF" then
		set myFolder to "PDFProofs:"
		set _dest to myFolder as Unicode text
		set screenSettings to PDF export preset "YOUR PDF PRESET NAME HERE"
		set page range of PDF export preferences to all pages
		set docName to name of document 1
		if docName ends with ".crtr" then
			set docName to text 1 thru -2 of docName
		end if
		
		tell application "Adobe InDesign CC 2015"
			export document 1 format PDF type to (_dest & docName & ".pdf") using screenSettings without options
			if modified of active document is true then
				tell active document to save
				close document 1
			end if
			(*
			tell PDF export preferences
				set view PDF to true
			end tell
			*)
		end tell
	end if
end tell

Hi Budgie,

Just a quick query for my reference.

Is the 2nd tell application “Adobe InDesign CC 2015” block required?
Or, could it just be part of the outer tell application block?

Thanks Budgie.

thank you for the help…

it does prompt for a PDF

but then errors at:

set screenSettings to PDF export preset “YOUR PDF PRESET NAME HERE”

is it looking for a name or a file path?? if it is looking for name…it would be the doc file name.pdf

Hi Rick,

Where Budgie’s code says “YOUR PDF PRESET NAME HERE”, you need to change the bit in the quotes to the name of your desired Adobe PDF preset.

HTH

hey TecNik

your right, no it doesn’t need to be there, just tested it with out it and it works fine

Rick_260
As TecNik says, replace “YOUR PDF PRESET NAME HERE” with the exact name of your PDF preset

thank you. duh lol ( i was over thinking it :wink: )

i need to figure out away to trim off the .indd from the resulting PDF name

in other words if i run the script on “Untitled-1” doc the resulting PDF is Untitled-1.indd.pdf it should be Untitled-1.PDF

i need to play around with

set docName to text 1 thru -2 of docName

(-6 works)


and the big question is how to incorporate the script so that whenever a document is saved it prompts you to PDF the doc.

in MultiAd you simply place the script into the “Attached Scripts” folder i am guessing there is more to it…if not impossible InDesign

thank you again!! Rick

here is the current script. i need to figure out how make it run every time the user saves the doc. (save or save as). the script should always be “on” and not activated manually…any thoughts??

set _ExportPDF to (display dialog “Send Proof?” with icon caution buttons {“Cancel”, “PDF”} default button 2)
tell application “Adobe InDesign CS6”
if button returned of _ExportPDF is “PDF” then
set myFolder to “PDFProofs:”
set _dest to myFolder as Unicode text
set screenSettings to PDF export preset “[High Quality Print]”
set page range of PDF export preferences to all pages
set docName to name of document 1
if docName ends with “.indd” then
set docName to text 1 thru -6 of docName
end if

	tell application "Adobe InDesign CS6"
		export document 1 format PDF type to (_dest & docName & ".pdf") using screenSettings without options
		if modified of active document is true then
			tell active document to save
			close document 1
		end if
		(*
       tell PDF export preferences
           set view PDF to true
       end tell
       *)
	end tell
end if

end tell

i am guess that i need to incorporate some form of event listener …which is specifically “listening” for “save”??

i am not sure how to do that nor do i know how to have the script activate at application start up??

You could add the script to the ‘Scripts’ window. You can find that under Window > Utilities > Scripts.
The user could then select the script from there.

Or, there’s always third-party apps which can be used to assign a script to a keyboard shortcut.
For example FastScripts.

HTH

adding it to the scripts window would still require the user to activate the script “manually” i.e. click on it. unfortunately, this doesn’t happen in reality lol.

the end user forgets to send the proof. that is why i want to tie it into an event such as “save”.

i thought of trying to making the script into a key combo but again it would require the user to remember to do it…

if they are prompted to send a proof every time they save…it eliminates a degree of human error

thank you for the suggestions…every idea helps

i did find the startup scripts folder in Indesign. I just have to figure out how to write it so that the script runs ons “save”

what your looking for is called an event listener, basically it waits for an event to occur, in your case your waiting for the
user to save, to have your script run.

You could do it via java script, but I don’t no how to write it, and put that script in your start up scripts folder, or you could try the below applescript set up.

  1. Save your main script to where ever you want it to reside, and get the path to it

  2. Put the path and the name of you script in the below script, then run it

open an indesign file and then goto save it, you should have your main script fire

set OnSaveScript to (path to desktop folder as string) & "Test.scpt" -- PATH TO YOUR SCRIPT
-- or
--set OnSaveScript to "Macintosh HD:Users:rick_260:Desktop:TEST.scpt" -- PATH TO YOUR SCRIPT
tell application "Adobe InDesign CC 2015"
	delete every event listener
	make new event listener with properties {event type:"beforeSave", handler:OnSaveScript, cancelable:true}
	--make new event listener with properties {event type:"beforeSaveAs", handler:OnSaveScript, cancelable:true}
	--make new event listener with properties {event type:"beforeSaveACopy", handler:OnSaveScript, cancelable:true}
end tell

To delete your event listeners, run this

tell application "Adobe InDesign CC 2015"
	delete every event listener
end tell