User interaction level problems when scripting in InDesign CS3

I have a script here that performs several operations to a group of documents, but it stops upon an encounter with an error regarding missing fonts or links. This script is intended to pick up where Automator left off and use files passed down to the script. Just an FYI, this part of the job executes just fine because the files open.

I get the error upon opening the files (5 total). That’s when I get “Cannot handle the request because a modal dialog or alert is active.” The alert in question has to do with modified links in the documents: “WW_color_spread.pdf” and “WW_bw_spread.pdf”

Since fonts aren’t a concern and a major operation in the script has to do with updating these links, I’m not interested in these error messages. I just want the script to run.

------- BEGIN SCRIPT -------

on run {input, parameters}
	
	-- Update links in document, export as PDF using a Press-optimized PDF, save and close.
	-- input:	Files/Folders
	-- output: none
	
	tell application "Adobe InDesign CS3"
		
		--Hoped that this would fix the modal dialog error, but it doesn't seem to work.
		set user interaction level of script preferences to never interact
		
		try
			--Open files brought in by Automator.
			open input
		end try
		
		--Set up counter to keep track of how many documents are left to modify.
		set numberOfDocs to count document
		
		--Set PDF preset to use when exporting PDFs.
		set myPreset to "WWH - Final PDF"
		
		--Repeat these functions for every document that's open.
		repeat while numberOfDocs is greater than 0
			
			--Set the frontmost document as the document to be modified.
			set myDoc to active document
			
			--Modify specified document.
			tell myDoc
				
				--Update the two links for this issue.
				try
					relink link "WW_bw_spread.pdf" to ((file path of myDoc as string) & "Links:WW_bw_spread.pdf")
				end try
				try
					update link "WW_bw_spread.pdf"
				end try
				try
					relink link "WW_color_spread.pdf" to ((file path of myDoc as string) & "Links:WW_color_spread.pdf")
				end try
				try
					update link "WW_color_spread.pdf"
				end try
				
				--Get file path and file name to use when exporting PDFs.
				set myDocPDFPath to ((file path of myDoc as string) & (name of myDoc as string))
				set theOffset to offset of ".indd" in myDocPDFPath
				set myDocPDFPath to (((characters 1 thru theOffset of myDocPDFPath) as string) & "pdf")
				
				--Export PDF using specified PDF preset, file path and file name.
				export myDoc format PDF type to myDocPDFPath using myPreset without showing options
				
				--Save document on top of itself.
				save
				
				--Close document.
				close
				
			end tell
			
			--Reduce document counter by 1.
			set numberOfDocs to numberOfDocs - 1
			
		end repeat
		
		set user interaction level of script preferences to interact with all
		
	end tell
	
end run

------- END SCRIPT -------

Thanks in advance for any help.

Model: Powermac G5, 2.3 GHz DP
AppleScript: 2.0
Browser: Firefox 2.0.0.11
Operating System: Mac OS X (10.5)

No ideas? Any help that anyone would be willing to offer would be really great. Thanks.

Hi,
I’ve tested the script below with a document that contains a font not active on my system and it opens the file without any dialogs. I then opened the file manually and the warning dialogs appeared as expected. Maybe you could try the same test on your machine as I can’t see that you’re doing anything wrong!!

set thefile to choose file
tell application "Adobe InDesign CS3"
	set user interaction level of script preferences to never interact
	open thefile
	set user interaction level of script preferences to interact with all
end tell

Thanks,
Nik

Hey, thanks for your help! :smiley: The script you provided made it simple and easy to narrow down the problem very quickly. The culprit seems to be… Suitcase Fusion. Anytime InDesign’s Suitcase Fusion plug-in is activated, the script doesn’t work. If I turn off the plug-in, the script runs as expected… perfectly.

Looks like I’ll need to bring this to Extensis’ attention.

Hi,
That’s great I’m glad you found a reason for the odd behavior.
I hope you resolve your issue and maybe post your results here when you get a fix, I’m sure somebody else we have a similar problem.
Thanks,
Nik

Since I seriously doubt you’ll get remedy from Extensis, three ideas:

–You could try to GUI that dialog shut via script.

–You could see if InDesign will allow you to script the turning on an off of plugins.

–You could see if Fusion will allow some level of control of those dialogs (I don’t recall seeing that in the preferences, but we only just switched from “regular” to Fusion in the last couple of weeks).

Tough nut to crack that one…

Good ideas. Since I can’t seem to find any means of handling dialogs via the dictionaries for either InDesign or Suitcase Fusion, this solution doesn’t seem likely. The first one seems intriguing… how do I “GUI that dialog shut via script?” It’s an expected error, and I’d prefer to leave Suitcase enabled in case I come across any files that need fonts to be activated.

Thanks for all the help. This is awesome.

I can’t give specific code (time constraints…kinda have to read-n-run unless it’s a project for my workplace), but assuming you know exactly where in your script the dialog intrudes, here are the theoretical steps:

–Using a try statement, catch the error. If you know this error and only this error will happen at a very specific point in your script, you can blindly make assumptions about it showing up. Using try will mean if the dialog isn’t there you can have it skip the “dialog dismissal” steps.

–Hopefully the dialog has an easy way to dismiss it in a default state, in which case use GUI scripting to keystroke a return to dismiss it (the big “if” in this theory…you might need something like UI Browser to try and see how the dialog is referenced). If you can’t “hit return” via GUI, you can try to get UI Scripting to click the appropriate button for you.

–Then continue your script on it’s merry way.

Someone here with more experimental time might be able to give you more specific steps. Sorry again for the hit-b-run theory…

No, that’s alright. This is good. I would’ve never thought of this myself. I’ll check it out.

Thanks to CalvinFold’s suggestion, I now have a workaround that works pretty well:

-- Update links in document, export as PDF using a Press-optimized PDF, save and close.
-- input:	Files/Folders
-- output: none

tell application "Adobe InDesign CS3"
	
	--Hoped that this would fix the modal dialog error, but it doesn't seem to work.
	set user interaction level of script preferences to never interact

	try
		--Open files brought in by Automator.
		open input
	end try
	
end tell

-- Kill the dumb dialog for missing links.
activate application "Adobe InDesign CS3"
tell application "System Events"
	get system attribute "sysv"
	if result is greater than or equal to 4144 then --Error Handler
		if UI elements enabled then
			tell application process "InDesign"
				delay 30 --(Gotta let InDesign catch up first.)
				key code 36 --Press "ENTER" --(I couldn't get a command to click the button to work. This works pretty well.)
			end tell
		else
			beep
			display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop
			if button returned of result is "OK" then
				tell application "System Preferences"
					activate
					set current pane to pane "com.apple.preference.universalaccess"
				end tell
			end if
		end if
	else
		beep
		display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
	end if
end tell

tell application "Adobe InDesign CS3"
	--Set up counter to keep track of how many documents are left to modify.
	set numberOfDocs to count document
	
	--Set PDF preset to use when exporting PDFs.
	set myPreset to "WWH - Final PDF"
	
	--Repeat these functions for every document that's open.
	repeat while numberOfDocs is greater than 0
		
		--Set the frontmost document as the document to be modified.
		set myDoc to active document
		
		--Modify specified document.
		tell myDoc
			
			--Update the two links for this issue.
			try
				relink link "WW_bw_spread.pdf" to ((file path of myDoc as string) & "Links:WW_bw_spread.pdf")
			end try
			try
				update link "WW_bw_spread.pdf"
			end try
			try
				relink link "WW_color_spread.pdf" to ((file path of myDoc as string) & "Links:WW_color_spread.pdf")
			end try
			try
				update link "WW_color_spread.pdf"
			end try
			
			--Get file path and file name to use when exporting PDFs.
			set myDocPDFPath to ((file path of myDoc as string) & (name of myDoc as string))
			set theOffset to offset of ".indd" in myDocPDFPath
			set myDocPDFPath to (((characters 1 thru theOffset of myDocPDFPath) as string) & "pdf")
			
			--Export PDF using specified PDF preset, file path and file name.
			export myDoc format PDF type to myDocPDFPath using myPreset without showing options
			
			--Save document on top of itself.
			save
			
			--Close document.
			close
			
		end tell
		
		--Reduce document counter by 1.
		set numberOfDocs to numberOfDocs - 1
		
	end repeat
	
	set user interaction level of script preferences to interact with all
	
end tell

Thanks, everyone, for your help.

I just wrote a script that had the same problem. Unfortunately, the script gets info from ID docs about the images, so it doesn’t aforehand which images to relink.

My inspiration was to write a tell block at the start of the script:


tell application "Adobe InDesign CS3"
set user interaction level of script preferences to never interact
end

then I put another tell block at the end


tell application "Adobe InDesign CS3"
set user interaction level of script preferences to interact with all
end

Weird thing is this made my script run entirely in the background. So I got the result, yet InDesign never showed me an application window, which is actually what I wanted.

If there is something wrong with that please inform me.

I actually wouldn’t mind having that run in the background myself, but ultimately I just want the dialog boxes to go away so that the script can do it’s thing. I’m interested to know what you find out, though.

Good luck! :smiley: