On Jul 7, 2010, at 11:21 AM, Jim Brandt wrote:
My question is:
is there a way to perform an action in System Events (in this case, the click UI element) and test to see if the action happens sucessfully?
GUI Scripting is based on Apple's accessibility API, which does generate a variety of errors in appropriate circumstances. I don't recall ever seeing an 'on error' statement triggered by an accessibility error in the GUI Scripting context, but it might happen if any of the accessibility errors do get passed on to the AppleScript 'on error' handler in a GUI Scripting script. Enclose the offending statement in a 'try'/'on error' block and see what happens.
Another possibility is to change the offending line so that it performs an "AXPress" action, instead of using the 'click' command. Theoretically, they should be the same, but in the past it has sometimes made a difference to perform an "AXPress" action.
As a last resort, it is sometimes useful to see whether a keyboard shortcut can be used to accomplish the same thing as a click. If so, then you can send a GUI Scripting 'keystroke' or 'keycode' command to Safari.
A longshot possibility is to see whether Safari posts an accessibility notification when you click that UI element. You can learn whether it does this by using UI Browser's Notifications Drawer to register for an appropriate notification, then monitor UI Browser's Notification Log window while you perform the action manually in Safari. This is a longshot, because it isn't clear to me which accessibility notification you would want to register for. But you might be able to hit on some appropriate notification by looking at the changes that occur in the Safari interface when you click the target UI element. If UI Browser does confirm that a notification is issued as a result of clicking that UI element, you might be able to watch for that notification in a companion script. GUI Scripting doesn't have this capability, but my UI Actions product does (or rather, it will once again when I release the next version in a couple of weeks). Watch this Web site for news about UI Actions: <
http://pfiddlesoft.com/uiactions/>.
A couple of comments:
2. At one point in your script, you use the GUI Scripting 'click at' command. You should be aware that, under the hood, GUI Scripting simply translates the specified location into a standard UI element reference and then clicks that UI element. It might be more reliable or at least a shade faster if you rewrote that line to click the UI element itself using the simple form of the 'click' command.