InDesign CS2: closing a dialog window

Hi,
I’m trying to write a script that’ll open a InDesign package folder and print the file. So far I’ve got this to work but if I open a document and the fonts aren’t loaded or the links are missing a diaolg window appears. I want to be able to close the dialog window and then close the document without any user intervention. Any ideas?
Here’s what I have so far!
Thanks

on open (source_folder)
	set collected_folder to item 1 of source_folder
	set ThePath to path to desktop as string
	set printstyle to "CMOT_to_Mosaic_PDF"
	
	tell application "Finder"
		set ad_folder to collected_folder as string
		set item_list to every file of the collected_folder
		repeat with i from 1 to the number of items of item_list
			set this_item to item i of item_list as alias
			set file_name to name of this_item
			set doc_info to info for this_item
			set doc_kind to kind of doc_info
			set doc_file_type to file type of doc_info
			if doc_kind contains "InDesign" and doc_file_type = "IDd4" then
				tell application "Adobe InDesign CS2"
					try
						activate
						open this_item
						set page_count to count pages of active document
						if page_count = 1 then
							print active document using printstyle without print dialog
							tell active document to save
							tell active document to close
						else if page_count > 1 then
							tell document 1
								set page range of print preferences to "1"
							end tell
							print active document using printstyle without print dialog
							tell active document to save
							set page_number to characters -1 thru -3 of file_name as string
							set new_page_number to page_number + 1 as string
							set char_count to count characters of new_page_number
							if char_count is equal to 1 then
								set new_new_page_number to "00" & new_page_number
							else if char_count is equal to 2 then
								set new_new_page_number to "0" & new_page_number
							else if char_count is equal to 3 then
								set new_new_page_number to new_page_number
							end if
							set new_file_name to characters 1 thru -4 of file_name & new_new_page_number as string
							save document 1 to (ad_folder & new_file_name)
							tell document 1
								set page range of print preferences to "2"
							end tell
							print active document using printstyle without print dialog
							tell active document to save
							tell active document to close
						end if
					on error
							tell application "Adobe InDesign CS2"
								quit
							end tell
							--error number -128
					end try
				end tell
			end if
		end repeat
		move collected_folder to "Macintosh HD:Users:nik:Desktop:auto_print_pages:0_Done"
	end tell
end open

Hi,

this is a routine to force a time out error and
close the window with UI scripting.
I don’t have InDesign CS2, maybe you get an NSevaluation error,
if window 1 is a sheet or something else, but it could work :wink:

try
	with timeout of 5 seconds
		quit application "Adobe InDesign CS2"
	end timeout
on error number e
	if e is -1712 then
		activate application "Adobe InDesign CS2"
		tell application "System Events"
			tell application process "Adobe InDesign CS2"
				click button "Don't Save" of window 1
			end tell
		end tell
	end if
end try

Hi Stefan,
Thanks for your response but unfortunately th code doesn’t seem to do anything, not even an error. I thought maybe I could use system events to click the “Don’t Fix” button if the fonts aren’t loaded but even though applescript’s result window tells me the button has been clicked the window does not dissapear.

tell application "System Events"
	tell process "Adobe InDesign CS2"
		tell window 1
			click button 2
		end tell
	end tell
end tell

My next attempt was to use a shell script to force InDesign to quit

do shell script "kill_pid=`ps ax | grep InDesign | grep -v grep | awk '{ print $1 }'`; kill $kill_pid"

This quits InDesign OK but next time I launch Indesign it uses the “Document Recovery” and opens the last file that was open before the Force Quit. The only way I can think of getting around this problem is to some how delete the temp recovery file so that next time InDesign opens it doesn’t open the last doc. Any suggestions would be greatfully appreciated.
Nik (blend3)

this will dismiss the dialog you can decide what to do from there


tell application "Adobe InDesign CS2"
	activate
	tell application "System Events"
		tell application process "Aobe InDesign CS2"
			if exists window "Missing Fonts" then
				keystroke return
			end if
		end tell
	end tell
end tell

mm

Hi,
Sadly I can’t this to wotk either. The best that I’ve come up with is “on error” force quit InDesign then delete the recovery files and re-launch InDesign. Still in the middle of testing this but I would still appreciate any better suggestions.
Thanks

try
	--do something
on error
	tell application "Finder"
		do shell script "kill_pid=`ps ax | grep InDesign | grep -v grep | awk '{ print $1 }'`; kill $kill_pid"
		tell application "Finder"
			set ind_recovery_Folder to folder "Macintosh HD:Users:nik:Library:Preferences:Adobe Indesign:Version 4.0:InDesign Recovery"
			delete every item of ind_recovery_Folder
			empty trash
			move collected_folder to "Macintosh HD:Users:nik:Desktop:auto_print_pages:0_Error"
		end tell
		tell application "Adobe InDesign CS2"
			activate
		end tell
	end tell
end try

blend3

did you try the post I put up last night ?

Hi, Yep I did try you post but again I couldn’t get it to work. I’m now trying to disable the user interaction and then check the fonts/links status from within InDesign, if the fonts or links aren’t active then error. Any further help is still appreciated. :confused:

set this_item to choose file
tell application "Adobe InDesign CS2"
	activate
	set user interaction level of script preferences to never interact
	open this_item
	tell document 1
		set myfontprop to properties of every font
		repeat with i from 1 to the number of myfontprop
			set this_font_item to item i of myfontprop
			set myfontname to name of this_font_item as string
			set fontstatus to status of this_font_item as string
			if fontstatus = "not available" then
				tell application "Adobe InDesign CS2"
					if document 1 exists then
						tell active document to close
						tell application "Finder"
							activate
							display dialog "A Font  is missing"
						end tell
					end if
				end tell
			end if
		end repeat
		tell application "Adobe InDesign CS2"
			if document 1 exists then
				tell document 1
					set mylinkprop to properties of every link
					repeat with i from 1 to the number of mylinkprop
						set this_link_item to item i of mylinkprop
						set mylinkname to name of this_link_item as string
						set linkstatus to status of this_link_item as string
						if linkstatus = "link missing" then
							tell application "Adobe InDesign CS2"
								if document 1 exists then
									tell active document to close
									tell application "Finder"
										activate
										display dialog "An Image  is missing"
									end tell
								end if
							end tell
						end if
					end repeat
				end tell
			end if
		end tell
	end tell
	set user interaction level of script preferences to interact with all
end tell

in your universal access preferences you need to activate “enable access for ssistive devices”

Hi,
Idouble checked and I’ve definately got “enable access for ssistive devices” enabled and still can’t get your code to work. Are you able to test this? I think I’m making progress with InDesign’s font/link status but any further ideas are greatfully welcomed!

blend

the code I gave you worked fine on my machine what is the error when you try to run it on stand alone on yours ?

It’s saying the window doesn’t exist, it returns false. I’ve made sure that the InDesign file is open and the active window is the “missing fonts” window.:confused:

there was a typo try this


tell application "Adobe InDesign CS2"
	activate
	tell application "System Events"
		application processes
		tell application process "Adobe InDesign CS2"
			name of window 1
			
			if exists window "Missing Fonts" then
				keystroke return
			end if
			
		end tell
	end tell
end tell

Hi,
That was the problem, Thanks very much for your help it makes the coding a lot shorter. I’ve tried this with the links window and it also works! :smiley:

I can’t believe I actually have something to contribute on such a dignified scripting forum. :slight_smile:

Why trap the error?

Why not set UserInteractionLevels to neverInteract ?
Then, at the end of your script set it back to interactWithAll :smiley:

I use that to bypass potential hangups while I’m archiving InDesign documents.

Hope that helps!

By the way, I use Javascript for everything, so I don’t have applescipt to post. Sorry… :frowning:

Here is the Javascript (Totally plagiarized, but I can’t remember where I found it):

if (app.version == 3) {
app.userInteractionLevel = UserInteractionLevels.neverInteract;
}
else {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
}

//Return to previous interaction state
if (app.version == 3) {
app.userInteractionLevel = UserInteractionLevels.interactWithAll;
}
else {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
}