Edit sacript for use in InDesign

Hi,

I’m new to AppleScript and we want to automate some of our daily tasks.

I found a AppleScript that works with a finder selection as input, than it opens the files in InDesign and exports a LR (named: “filename_LR.pdf”) and a HR pdf (named: “filename_HR.pdf”) to a folder named MyFolder on my desktop using 2 different pdf presets.
I want to change the script so it works from the script pallet in InDesign, the LR and HR pdf’s should be placed in the same folder as the original InDesign file.

tell application "Finder"
	set myfiles to the selection
end tell

tell application "Finder"
	if not (exists folder "myFolder") then
		make new folder at desktop with properties {name:"myFolder"}
	end if
end tell

tell application "Adobe InDesign CS5.5"
	activate
	repeat with i in myfiles
		open (i as alias)
		
		tell every document
			set visible of layer "Paginabegrenzing" to true -- or false as needed
		end tell
		set thePreset to "_Ende_LR"
		
		set theDesk to (path to desktop as string) & "myFolder:"
		set f to (name of i as string)
		set thepath to theDesk & f
		
		if thepath ends with ".indd" then set thepath to text 1 thru -6 of thepath
		
		export document 1 to file (thepath & "_LR.pdf") format PDF type using PDF export preset thePreset without showing options
			
		tell every document
			set visible of layer "Paginabegrenzing" to false -- or true as needed
		end tell
		set thePreset to "_Ende_HR"
		
		set theDesk to (path to desktop as string) & "myFolder:"
		set f to (name of i as string)
		set thepath to theDesk & f
		
		if thepath ends with ".indd" then set thepath to text 1 thru -6 of thepath
		
		export document 1 to file (thepath & "_HR.pdf") format PDF type using PDF export preset thePreset without showing options
		
		--		close active document saving no
	end repeat
end tell

Model: iMac
AppleScript: 2.1.2
Browser: Safari 534.52.7
Operating System: Mac OS X (10.6)

Hi Zip
Cut and paste this into AppleScript Editor, and save it as a text file, place it in the Indesign scripts folder, the code presumes that you have a folder already on the desktop and that your ID file is in that folder with a layer called “Paginabegrenzing”

(tested under OSX 10.6.8, Indesign CS5.5)

tell application "Adobe InDesign CS5.5"
	if (count documents) > 0 then
		my DoMyCode()
	else
		display dialog "No documents are open."
	end if
end tell
on DoMyCode()
	tell application "Adobe InDesign CS5.5"
		activate
		set mydOC to active document
		tell active document
			set visible of layer "Paginabegrenzing" to true -- or false as needed
		end tell
		set thePreset to "_Ende_LR"
		set theDesk to (path to desktop as string) & "myFolder:"
		set f to (name of mydOC as string)
		set thepath to theDesk & f
		
		if thepath ends with ".indd" then set thepath to text 1 thru -6 of thepath
		export document 1 to file (thepath & "_LR.pdf") format PDF type using PDF export preset thePreset without showing options
		
		tell active document
			set visible of layer "Paginabegrenzing" to false -- or true as needed
		end tell
		set thePreset to "_Ende_HR"
		set theDesk to (path to desktop as string) & "myFolder:"
		set f to (name of mydOC as string)
		set thepath to theDesk & f
		
		if thepath ends with ".indd" then set thepath to text 1 thru -6 of thepath
		export document 1 to file (thepath & "_HR.pdf") format PDF type using PDF export preset thePreset without showing options
		
		--close active document saving no
	end tell
end DoMyCode

Hi Budgie,

Thanx for your reply, works great from the scriptspanel in InDesign.
There’s only one thing that isn’t working like i would want it to work.
The HR and LR pdf are now saved in folder called “MyFolder” on the desktop, I would like them to be saved on the same drive and folder that the original InDesign files are stored.

Thanx in advance!

gidday

give this a crack Zip.

tell application "Adobe InDesign CS5.5"
	if (count documents) > 0 then
		my DoMyCode()
	else
		display dialog "No documents are open."
	end if
end tell
on DoMyCode()
	tell application "Adobe InDesign CS5.5"
		activate
		set mydOC to active document
		tell active document
			set visible of layer "Paginabegrenzing" to true -- or false as needed
		end tell
		set thePreset to "_Ende_LR"
		tell application "Finder"
			set theDesk to selection as Unicode text
		end tell
		
		set f to (name of mydOC as string)
		set thepath to theDesk --& f
		
		if thepath ends with ".indd" then set thepath to text 1 thru -6 of thepath
		export document 1 to file (thepath & "_LR.pdf") format PDF type using PDF export preset thePreset without showing options
		
		tell active document
			set visible of layer "Paginabegrenzing" to false -- or true as needed
		end tell
		set thePreset to "_Ende_HR"
		tell application "Finder"
			set theDesk to selection as Unicode text
		end tell
		
		set f to (name of mydOC as string)
		set thepath to theDesk --& f
		
		if thepath ends with ".indd" then set thepath to text 1 thru -6 of thepath
		export document 1 to file (thepath & "_HR.pdf") format PDF type using PDF export preset thePreset without showing options
		
		--close active document saving no
	end tell
end DoMyCode

Thank you Budgie,

Works perfect! :slight_smile:

I still have some issues with the script.

When the document is exported as a pdf before, with a name like “DocmentName_proef.pdf”, the next time i open the document and run the script i get pdf’s with names like: “DocmentName_proef.pdf_LR.pdf”.

Sometimes the pdf’s are saved in the root of my HD with the names “_LR.pdf” and “_HR.pdf”.

Hi,

Found out why the pdf’s are sometimes saved in my home folder on the HD.

		tell application "Finder"
			set theDesk to selection as Unicode text
		end tell

When there was nothing selected in the finder, InDesign would save the file to my home folder and named them “_LR.pdf” and “_LR.pdf”.

I changed the script (see below) and it seems to be working even if there is nothing selected in the finder.

tell application "Adobe InDesign CS5.5"
	if (count documents) > 0 then
		my DoMyCode()
	else
		display dialog "No documents are open."
	end if
end tell
on DoMyCode()
	tell application "Adobe InDesign CS5.5"
		activate
		set mydOC to active document
		
		tell active document
			set visible of layer "Paginabegrenzing" to true
		end tell
		set thePreset to "_Ende_LR"
		set theDesk to file path of mydOC as string
		set f to (name of mydOC as string)
		set thepath to theDesk & f
		if thepath ends with ".indd" then set thepath to text 1 thru -6 of thepath
		export document 1 to file (thepath & "_LR.pdf") format PDF type using PDF export preset thePreset without showing options
		
		
		tell active document
			set visible of layer "Paginabegrenzing" to false
		end tell
		set thePreset to "_Ende_HR"
		set theDesk to file path of mydOC as string
		set f to (name of mydOC as string)
		set thepath to theDesk & f
		if thepath ends with ".indd" then set thepath to text 1 thru -6 of thepath
		export document 1 to file (thepath & "_HR.pdf") format PDF type using PDF export preset thePreset without showing options
		
	end tell
end DoMyCode

:slight_smile: