Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Using AppleScript UI scripting on AXUnknown elements System
While it's great that UI Scripting has been integrated into Panther, it has some potholes compared to its earlier Jaguar incarnation. Specifically, many of the user interface items you'd like to script (for instance, the "Show Icon Preview" checkbox in view options) are children of "AXUnknown". This effectively prevents you from using:

click checkbox "Show Icon Preview" of window "Show View Options"
To work around this, use the UIElementInspector to "lock on" (Command-F7 while hovering) to the item you want to script. For any locked item in the UI Element Inspector, you can refer to its children by their position on the "goto->AXChildren" popup menu in the "Locked on" inspector window. So if a given UI item has three children (say AXUnknown, AXCheckBox, AXSomethingOrOther), then you can refer to AXUnknown using UI Element 1 of item. This can be used to script user interface elements that are children of AXUnknowns, which are otherwise unscriptable.

For example, say you want to script the "Show Icon Preview" checkbox in "View Options". According to the UI Element Inspector, it is [check box whose title is "Show icon preview" of AXUnknown of AXUnknown of window "View Options"]. However, these AXUnknown's aren't scriptable in this manner, so you need their raw UI Element ID's. To find these, navigate to the parent and look at its list of children. If there are multiple AXUnknown's you may have to dig through their children to determine which is the AXUnknown you're looking for. After doing this, you can determine that UI element 3 and UI element 1 are the first and second "AXUnknown" items above the "Show Icon Preview" checkbox, so you can script it as follows:

  tell UI element 3 of window 1
    click radio button "This window only"
     of radio group 1 of UI element 2
    set uiSIP to checkbox "Show Icon Preview" of UI element 1
    if the value of uiSIP is 0.0 then click uiSIP
  end tell
Thanks to Randall Million of Plaid Cow Solutions for the original script that led me to discovering this (and using it all over the place!).
    •    
  • Currently 2.00 / 5
  You rated: 2 / 5 (7 votes cast)
 
[18,095 views]  

10.3: Using AppleScript UI scripting on AXUnknown elements | 5 comments | Create New Account
Click here to return to the '10.3: Using AppleScript UI scripting on AXUnknown elements' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Using AppleScript UI scripting on AXUnknown elements
Authored by: dahjelle on Dec 03, '03 12:27:06PM

Perhaps a bit off topic, but has anyone managed to UI script the print dialogs or sheets in Panther? I spent a good chunk of last weekend trying to get it to work, but didn't have any success.

Perhaps it was due to my inexperience with AppleScript.

Thanks for any hints you might have!



[ Reply to This | # ]
10.3: Using AppleScript UI scripting on AXUnknown elements
Authored by: mdc1952 on Dec 03, '03 01:00:22PM

I've tried it once so far; it would sure help if there were more documentation about GUI scripting. I did get a test script to work to save as a postscript file, but it took awhile to figure out how to get the dialog configured. I used both Apple's and Prefab's Element Inspector until I found some example somewhere that finally cracked how to get to the output options. I think it was bascially the problem outlined in this hint. The relevant portion of the code was:
click menu item "Print…" of menu "File" of menu bar 1
click pop up button 1 of window "Print"
click menu item 3 of menu 1 of pop up button 1 of window "Print"
delay 1
click checkbox "Save as File" of UI element 1 of UI element 3 of window "Print"
click pop up button 1 of UI element 1 of UI element 3 of window "Print"

click menu item 2 of menu 1 of pop up button 1 of UI element 1 of UI element 3 of window "Print"
delay 1
click button "Save…" of UI element 4 of window "Print"


I then had to use the keystroke command to spell out the file name I wanted as I couldn't find away to just set it from a variable (i'm not sure if I tried just pasting it".



[ Reply to This | # ]
10.3: Using AppleScript UI scripting on AXUnknown elements
Authored by: xyz3 on Dec 03, '03 09:40:01PM

ACK!

Try scripting creating a new user, and setting the autologin to that user. I had it working in 10.2, and lo and behold, there is this new user UI which scripting can't get to...

Anyhow - after a bit of messing with shell scripts and niutil I have the account creation working, but still can't seem to set the autologin..

I have been biting my tongue for awhile on this now, but UI scripting is a lame reason for developers to not include proper AppleScript support.



[ Reply to This | # ]
10.3: Using AppleScript UI scripting on AXUnknown elements
Authored by: DeltaTee on Dec 05, '03 12:45:07PM

I thought the code looked a little bit familiar...thanks for cleaning it up and for the attribution.

GUI scripting is good, but there are a few caveats:
- Scripting is tied way too closely to the implementation. I should be able to refere to a button of a window without worrying about what groups it is a part of.
- Scripting is not available for all applications. Some applications are simply not GUI scriptable with any consistency. (Like iTunes)



[ Reply to This | # ]
10.3: Using AppleScript UI scripting on AXUnknown elements
Authored by: diamondsw on Dec 05, '03 03:24:04PM

Thanks for the original code. :) Yes, this is a last resort, and programs that use seriously non-standard UI elements still won't be scriptable. However, this works for a lot of things (save dialogs, view options, etc). What I think would be great is if AppleScript could record such UI interactions. If the program is "recordable", use high-level events. If not, record the UI interaction. Maybe in 10.4? :)



[ Reply to This | # ]