System Events not working correctly with Acrobat Professional

Hey Guys, I have a script that I have written that automatically enables security settings on a PDF through Acrobat Professional. Because of Acrobats poor scriptability I am forced into doing much though System Events.

This is not a major problem… however when activating some settings in the security settings, often warning Alert dialog boxes appear when you tell System Events to enable particular settings. These Alerts do not have a title… The only way I have been able to get the script to deal with them is with the following code:


if title of front window is "" then
	tell front window
		click button "OK"
	end tell
end if

I guess this is an ok solution… bit hard to identify windows when they don’t have titles…

BUT this is not my main problem. The main problem is that the script gets to one of these alert dialog boxes and just sits there… It sits there for like 10 seconds and then it performs the “click button “OK”” command.

This is a problem as there are like 3 of these instances and it really adds up. Can anybody help me… I am using Acrobat Professional 8.2.0 and the entire code is:


tell application "System Events"
	try
		tell process "Acrobat"
			
			-- Enable security settings
			click menu item "Properties..." of menu "File" of menu bar item "File" of menu bar 1
			tell window "Document Properties"
				tell tab group 1
					click radio button "Security"
					tell group "Document Security"
						click pop up button 1
						click menu item 2 of menu 1 of pop up button 1
					end tell
				end tell
			end tell
			tell window "Password Security - Settings"
				click pop up button 1
				click menu item 4 of menu 1 of pop up button 1
				tell group "Permissions"
					click checkbox "Restrict editing and printing of the document. A password will be required in order to change these permission settings."
					click text field 1
					keystroke pdfPassword
					click pop up button 1
					click menu item 2 of menu 1 of pop up button 1
					click pop up button 2
					click menu item 4 of menu 1 of pop up button 2
				end tell
				click button "OK"
			end tell
			if title of front window is "" then
				tell front window
					click checkbox 1
					click button "OK"
				end tell
			end if
			tell window "Adobe Acrobat - Confirm Permissions Password"
				click text field 1
				keystroke pdfPassword
				click button "OK"
			end tell
			if title of front window is "" then
				tell front window
					click checkbox 1
					click button "OK"
				end tell
			end if
			tell window "Document Properties"
				click button "OK"
			end tell
end tell
	on error
		display alert "System Events was unable to Enable Commenting. This may be because Acrobat has modified its menu system. Please contact your system administrator."
	end try
end tell

I have never tried gui scripting with Acrobat, but i can tell you that in my past experience with gui scripting you usually want to put in a

delay 1

previous to the popup displaying. I found that this gives the popup time to load and be ready to respond instantly. The delay can be adjusted to whatever works best. I’m not sure if this will help you but I know I have seen the problem you are having with other programs and this fixed it.

Dallas

Yeah I did try this… But it didn’t help. its funny… its like as soon as I click the “OK” button it stalls for 10 seconds or does not know that is meant to continue… because I did this


tell window "Password Security - Settings"
	click button "OK"
end tell
beep

In this situation it still takes like 10 seconds for the beep to occur after the click button “OK” command.