I purchased an application which has no native Applescript support. There is a dialog box that pops up after a process of indeterminate length completes. When the dialog appears, I need Applescript to select one of the its buttons but the dialog has no title. Thanks for any advice!
the only way to accomplish that is GUI scripting, but this strongly depends on the UI structure of the app.
activate application "myApp" tell application "System Events" tell process "myApp" repeat until exists window "Dialogbox" delay 1.0 end repeat tell window "Dialogbox" to click button "theButton" end tell end tell
the process name, window name and button name are crucial and must match exactly the appropriate names.
But even then there is no guarantee that the script works.
The window could be a sheet and the button could be inside a box or other UI element.
Get yourself UI Element Inspector, if you have Access to Assistive devices enabled in the System Preferences pane, then you can use it to read off the values. You’ll find the values for the UI Elements in the dictionary of System Events.
Looking at some scripts around here can be helpful.
Stefan beat me to it.
As Stefan has said, you’ll need to use GUI Scripting (for which “Enable access for assistive devices” needs to be enabled in System Preferences’s “Universal Access” pane). It’s very likely that the dialog box will be the front window of the application process while it’s showing. If so, your script will need to use a delay loop to wait until the front window of the process contains some element which can only belong to the dialog.
However, to find out what that is while you’re writing the script, you’ll need to experiment. I myself would do manually whatever leads to the opening of the dialog, then, with the dialog open, run an exploratory script like this one, which can list the window’s entire GUI-Scriptable contents in a TextEdit window. That should give you (or us) a few clues as to how to click the button you’re after.
Thanks to all three of you! So I’m downloading Apple’s developer tools and will try what McUsrII had suggested. In the meantime I ran the script that Nigel had suggested. Here is the result:
window 1 of application process “3D Issue Lite” of application “System Events”
UI element 1
static text “Do you wish to add this publication to the online archive?”
There is a ‘cancel’ dialog which is present the entire time the app is processing the document. That window name is “3D Issue.” Could Applescript do kind of a ‘when window does not exist’ thing and then trigger the remaining script steps? Is so, might you direct me to an example?
I don’t fully understand what you mean.
Could you please add some more context, and elaborate a little?
What kind of dialog is open all the time? Is it this, or another one, and what are the following steps?