This script works,except I can't get the PDF's to close and save

Hello,
I have this great script that opens either In Design or Quark files and creates a PDF file.
The Quark part works perfect (by passing all dialog boxes and saving the PDF’s in a folder called “Babs PDF Folder”.
However, the InDesign Part opens the InDesign Files and creates the PDF file, but just leaves them open, leaving me to save them one at a time.
Can anyone figure out how to get the PDFs to save in that same Folder and close them once done?

thanks
babs

property Babs_Folder : "Babs PDF Folder"
global deskPath
global PathToFolder
global PathToFolder2
global tempPictures


on open thefiles
	tell application "Finder"
		activate
		set tempPictures to (every item of (get selection)) -- MUST GET BEFORE MAKING FOLDERS
		if not (exists folder Babs_Folder) then make new folder with properties {name:Babs_Folder}
		set deskPath to path to desktop as Unicode text
		set PathToFolder to POSIX path of (deskPath & Babs_Folder)
		set PathToFolder2 to deskPath & Babs_Folder
	end tell
	my openfiles()
	say "Finished"
end open

on openfiles()
	try
		tell application "Finder"
			repeat with LoopFiles in tempPictures
				set foundImages to {}
				if kind of LoopFiles = "Folder" then
					try
						set foundImages to files of entire contents of LoopFiles as list
					on error
						set foundImages to files of entire contents of LoopFiles
					end try
				else
					if kind of LoopFiles is not in {"Volume", "Disk Image", "Application", "Web Internet Location", "Document", "Text Clipping"} then
						set end of foundImages to LoopFiles
					end if
				end if
				--set WorkingFile to item i of fileList
				repeat with WorkingFile in foundImages
					if not ((kind of WorkingFile starts with "Quark") or (kind of WorkingFile starts with "InDesign")) then
						activate
						display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 1
					else
						--Determine whether to use InDesign subroutines or Quark subroutines
						if (kind of WorkingFile starts with "InDesign") then -- Process as InDesign
							my createInDesignPDF(WorkingFile, Babs_Folder)
						else -- Process as Quark
							my createQuarkPDF(WorkingFile)
						end if
					end if
				end repeat
			end repeat
		end tell
	on error errmsg
		display dialog "OpenFiles." & return & errmsg giving up after 20
	end try
end openfiles


on createInDesignPDF(WorkingFile, savePath)
	set x to 0
	repeat
		if x = 0 then
			set newpart to ""
		else
			set newpart to " " & x
		end if
		tell application "Finder"
			set tempname to my add_extension(WorkingFile, newpart, "pdf")
			if not (exists file tempname in folder Babs_Folder) then exit repeat
		end tell
		set x to x + 1
	end repeat
	tell application "Adobe InDesign CS3"
		try
			try
				set user interaction level of script preferences to never interact
			end try
			open WorkingFile as alias
			delay 2
			repeat
				if exists document 1 then exit repeat
				delay 0.2
			end repeat
			set theProps to properties of PDF export preset "[Press Quality]"
			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 & tempname) without showing options
			set properties of PDF export preferences to oldProps
			delay 1
			tell documents to close saving no
			try
				set user interaction level of script preferences to interact with all
			end try
		on error errmsg
			display dialog "CreateIndesignPDF." & return & errmsg giving up after 20
		end try
	end tell
end createInDesignPDF

on createQuarkPDF(WorkingFile)
	try
		set x to 0
		repeat
			if x = 0 then
				set newpart to ""
			else
				set newpart to " " & x
			end if
			tell application "Finder"
				set tempname to my add_extension(WorkingFile, newpart, "pdf")
				if not (exists file tempname in folder Babs_Folder) then exit repeat
			end tell
			set x to x + 1
		end repeat
		tell application "QuarkXPress"
			activate
			open WorkingFile as alias with Suppress All Warnings
			tell application "System Events" to 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 1
				keystroke tempname
				delay 1
				keystroke "G" using {shift down, command down}
				delay 1
				keystroke PathToFolder
				delay 1
				click button "Go" of sheet 1 of window "Export as PDF"
			end tell
			repeat 2 times
				delay 1
				activate
				tell application "System Events" to tell process "QuarkXPress"
					try
						if exists button "OK" of window 1 then
							click button "OK" of window 1
						end if
					end try
				end tell
			end repeat
			delay 1
			tell application "System Events" to tell process "QuarkXPress"
				try
					click button "Save" of window "Export as PDF"
				end try
			end tell
			repeat 4 times
				delay 1
				activate
				tell application "System Events" to tell process "QuarkXPress"
					try
						if exists button "OK" of window 1 then
							click button "OK" of window 1
						end if
					end try
					try
						if exists button "List Profiles" of window 1 then
							click button "Continue" of window 1
						end if
					end try
				end tell
			end repeat
			delay 2
			close front document saving no
		end tell
	on error errmsg
		display dialog "CreateQuarkPDF." & return & errmsg giving up after 20
	end try
end createQuarkPDF

on add_extension(WorkingFile, new_part, new_extension)
	try
		set this_info to info for WorkingFile as alias
		set this_name to the name of this_info
		set this_extension to the name extension of this_info
		if this_extension is missing value then
			set the default_name to this_name
		else
			set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
		end if
		return (the default_name & new_part & "." & the new_extension)
	on error errmsg
		display dialog "add extension " & return & errmsg
	end try
end add_extension

Hi,
Try this:

set WorkingFile to choose file

tell application "Adobe InDesign CS3"
	try
		set user interaction level of script preferences to never interact
		open WorkingFile as alias
		set filename to name of document 1
		if filename ends with ".indd" then set filename to text 1 thru -6 of filename
		set savePath to file path of document 1
		set theProps to properties of PDF export preset "[Press Quality]"
		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 as string) & filename & ".pdf") without showing options
		set properties of PDF export preferences to oldProps
		close active document saving no
		set user interaction level of script preferences to interact with all
	on error errmsg
		display dialog "CreateIndesignPDF." & return & errmsg giving up after 20
		set user interaction level of script preferences to interact with all
	end try
end tell

Thanks,
Nik

Hi,

pass PathToFolder2 instead of Babs_Folder in the handler call.

The “root” folder in a Finder tell block is the current desktop, for all other applications you have to specify the full path

Hi guys…
Nik, I tried your script but it didn’t work…
Stefen, I must be replacing it in the wrong place, cause I can’t get it to compile when I put it some places, and others places it compiles, but then the script dies. Babs_Folder is in a few spots, so maybe I am replacing the wrong one?
thanks
babs

just in this line


 my createInDesignPDF(WorkingFile, PathToFolder2)

PS: and change this

 
set PathToFolder2 to deskPath & Babs_Folder & ":"

Hey Stefen,

OK…I did that, and I am getting an error regarding "can’t make class desk of application “Finder” into type constent??
here is my current script with the changes.
thanks!

property Babs_Folder : "Babs PDF Folder"
global deskPath
global PathToFolder
global PathToFolder2
global tempPictures


on open thefiles
	tell application "Finder"
		activate
		set tempPictures to (every item of (get selection)) -- MUST GET BEFORE MAKING FOLDERS
		if not (exists folder Babs_Folder) then make new folder with properties {name:Babs_Folder}
		set deskPath to path to desktop as Unicode text
		
		set PathToFolder to POSIX path of (deskPath & Babs_Folder)
		set PathToFolder2 to deskPath & Babs_Folder & ":"
	end tell
	my openfiles()
	say "Finished"
end open

on openfiles()
	try
		tell application "Finder"
			repeat with LoopFiles in tempPictures
				set foundImages to {}
				if kind of LoopFiles = "Folder" then
					try
						set foundImages to files of entire contents of LoopFiles as list
					on error
						set foundImages to files of entire contents of LoopFiles
					end try
				else
					if kind of LoopFiles is not in {"Volume", "Disk Image", "Application", "Web Internet Location", "Document", "Text Clipping"} then
						set end of foundImages to LoopFiles
					end if
				end if
				--set WorkingFile to item i of fileList
				repeat with WorkingFile in foundImages
					if not ((kind of WorkingFile starts with "Quark") or (kind of WorkingFile starts with "InDesign")) then
						activate
						display dialog "This file is not an InDesign or Quark document!" buttons "Skipping" default button "Skipping" with icon 0 giving up after 1
					else
						--Determine whether to use InDesign subroutines or Quark subroutines
						if (kind of WorkingFile starts with "InDesign") then -- Process as InDesign
							my createInDesignPDF(WorkingFile, PathToFolder2)
						else -- Process as Quark
							my createQuarkPDF(WorkingFile)
						end if
					end if
				end repeat
			end repeat
		end tell
	on error errmsg
		display dialog "OpenFiles." & return & errmsg giving up after 20
	end try
end openfiles


on createInDesignPDF(WorkingFile, savePath)
	set x to 0
	repeat
		if x = 0 then
			set newpart to ""
		else
			set newpart to " " & x
		end if
		tell application "Finder"
			set tempname to my add_extension(WorkingFile, newpart, "pdf")
			if not (exists file tempname in folder Babs_Folder) then exit repeat
		end tell
		set x to x + 1
	end repeat
	tell application "Adobe InDesign CS3"
		try
			try
				set user interaction level of script preferences to never interact
			end try
			open WorkingFile as alias
			delay 2
			repeat
				if exists document 1 then exit repeat
				delay 0.2
			end repeat
			set theProps to properties of PDF export preset "[Press Quality]"
			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 & tempname) without showing options
			set properties of PDF export preferences to oldProps
			delay 1
			tell documents to close saving no
			try
				set user interaction level of script preferences to interact with all
			end try
		on error errmsg
			display dialog "CreateIndesignPDF." & return & errmsg giving up after 20
		end try
	end tell
end createInDesignPDF

on createQuarkPDF(WorkingFile)
	try
		set x to 0
		repeat
			if x = 0 then
				set newpart to ""
			else
				set newpart to " " & x
			end if
			tell application "Finder"
				set tempname to my add_extension(WorkingFile, newpart, "pdf")
				if not (exists file tempname in folder Babs_Folder) then exit repeat
			end tell
			set x to x + 1
		end repeat
		tell application "QuarkXPress"
			activate
			open WorkingFile as alias with Suppress All Warnings
			tell application "System Events" to 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 1
				keystroke tempname
				delay 1
				keystroke "G" using {shift down, command down}
				delay 1
				keystroke PathToFolder
				delay 1
				click button "Go" of sheet 1 of window "Export as PDF"
			end tell
			repeat 2 times
				delay 1
				activate
				tell application "System Events" to tell process "QuarkXPress"
					try
						if exists button "OK" of window 1 then
							click button "OK" of window 1
						end if
					end try
				end tell
			end repeat
			delay 1
			tell application "System Events" to tell process "QuarkXPress"
				try
					click button "Save" of window "Export as PDF"
				end try
			end tell
			repeat 4 times
				delay 1
				activate
				tell application "System Events" to tell process "QuarkXPress"
					try
						if exists button "OK" of window 1 then
							click button "OK" of window 1
						end if
					end try
					try
						if exists button "List Profiles" of window 1 then
							click button "Continue" of window 1
						end if
					end try
				end tell
			end repeat
			delay 2
			close front document saving no
		end tell
	on error errmsg
		display dialog "CreateQuarkPDF." & return & errmsg giving up after 20
	end try
end createQuarkPDF

on add_extension(WorkingFile, new_part, new_extension)
	try
		set this_info to info for WorkingFile as alias
		set this_name to the name of this_info
		set this_extension to the name extension of this_info
		if this_extension is missing value then
			set the default_name to this_name
		else
			set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
		end if
		return (the default_name & new_part & "." & the new_extension)
	on error errmsg
		display dialog "add extension " & return & errmsg
	end try
end add_extension

in the open handler change


.
	set deskPath to desktop as text
.

the Finder has a property desktop

OK…working and putting them in the folder…
Only thing it still won’t do is close the documents once they are opened in acrobat…
any thoughts there, and then she is done!
thanks
babs

change


tell documents to close saving no

into


close front document saving no

and you can omit


 repeat
     if exists document 1 then exit repeat
     delay 0.2
end repeat

AppleScript waits

Barbara, in the line:
set newProps to {view PDF:true, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps

why not set the boolean “view PDF” to false and see how you go? Like this:

set newProps to {view PDF:false, crop marks:false, bleed marks:false, color bars:false, registration marks:false} & theProps

thanks so much!!1
they are making me shut down…of course I will try it when I get home…
will keep you posted, but I am sure it will work :wink:
:slight_smile:

Hi Mark and Stefen,
I tried it both ways and they were both successful!!!
thanks as always for the help :wink:
It is always greatly appreciated!!!
babs