InDesign to PDF script

Hi,

Many, many years ago I used to do a bit of scripting as part of my job. It’s been awhile and I am very rusty! But I have managed to pull the below together to achieve the following task. Open all InDesign files output 2 pdfs of each file with certain layers visible then close the file.

At the moment it feels a bit clunky, it opens all the files in one go, then iterates through the layer/pdf process. I would prefer it to open 1 file at a time perform the action then close and move on to the next. I am hoping this would run smoother/quicker. Any suggestions on how to achieve this or improve the script would be greatly appreciated! As mentioned it been several years so apologies if the script looks bad!

Please note, with regard to the pdf preset, I want to use the standard one I use but with additional preferences just when I am using this script, which is why they extra prefs are there!

set thefolder to (choose folder with prompt "Choose the top level artwork folder" default location path to desktop)
set choFolder to quoted form of POSIX path of thefolder

--> spotlight searches <--
set theFiles to "\"kMDItemFSName == '*.indd'\""
set command to "mdfind -onlyin " & choFolder & " " & theFiles
set foundFiles to paragraphs of (do shell script command)

--> Batch process
tell application "Adobe InDesign 2020"
	activate
	open foundFiles
	repeat with myfile in every document
		set properties of PDF export preferences to properties of PDF export preset "My PDF Preset"
		set view PDF of PDF export preferences to false
		set export layers of PDF export preferences to false
		set pdfName to full name of active document as Unicode text
		--> Cutter pdf
		tell active document
			set properties of layers to {visible:false}
			set properties of layer "Cutter" to {visible:true}
		end tell
		export active document format PDF type to pdfName & "-cutter.pdf" without showing options
		--> Artwork pdf
		tell active document
			set properties of layers to {visible:true}
			set properties of layer "Cutter" to {visible:false}
		end tell
		export active document format PDF type to pdfName & "-artwork.pdf" without showing options
		close active document saving no
	end repeat
end tell

I don’t own InDesign so I can’t compile and test but you may try:

set thefolder to (choose folder with prompt "Choose the top level artwork folder" default location path to desktop)
set choFolder to quoted form of POSIX path of thefolder

--> spotlight searches <--
set theFiles to "\"kMDItemFSName == '*.indd'\""
set command to "mdfind -onlyin " & choFolder & " " & theFiles
set foundFiles to paragraphs of (do shell script command)

tell application "Adobe InDesign 2020"
	activate
	repeat with myFile in foundFiles
		open myFile
		set properties of PDF export preferences to properties of PDF export preset "My PDF Preset"
		set view PDF of PDF export preferences to false
		set export layers of PDF export preferences to false
		set pdfName to full name of active document as Unicode text
		--> Cutter pdf
		tell active document
			set properties of layers to {visible:false}
			set properties of layer "Cutter" to {visible:true}
		end tell
		export active document format PDF type to pdfName & "-cutter.pdf" without showing options
		--> Artwork pdf
		tell active document
			set properties of layers to {visible:true}
			set properties of layer "Cutter" to {visible:false}
		end tell
		export active document format PDF type to pdfName & "-artwork.pdf" without showing options
		close active document saving no
	end repeat
end tell

which is supposed to open/treat one document at a time.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 29 novembre 2019 11:40:07

Thanks, that does the trick!