Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Applescript in which I wish to set the value of the text fields Name and Password of a window belonging to the process SecurityAgent.

It is similar to the following:

tell window "Authenticate" of process "SecurityAgent"
    tell group 1
        set value of text field 1 to "king"
        set value of text field 2 to "king1"
    end tell
    click button "OK" of group 2
end tell 

While my script is also referring to the process SecurityAgent, the window in question is the one that pops up when you shut down OS X, and another user is logged in. The SecurityAgent window pops up asking for the administrator username and password in order to complete the shut down process. I do not know how to refer to the text fields in said window.

My question is, how do I find out the name of these text fields, the group they belong to, and the window they belong to? Is there a method of mapping OS X windows so I can refer to them in the AppleScript? I can't seem to find information concerning this anywhere.

share|improve this question
up vote 7 down vote accepted

I once tried to click a button in the Image Capture application and it took me a while to find this particular button. As explained in my question / answer there, there is a way, using the UIElementInspector. You can download it for free from Apple (download link is at the top in a button, direct link here).

It allows you to peek into the UI elements of each window you're hovering. Pressing Cmd-F7 locks its contents to the element you're hovering.

enter image description here

The "fun" part is actually figuring out how the window is grouped, and which elements belong to which parent. The $55 application UI Browser claims to do a better job at this.

When you're manually debugging AppleScript, and you are in the scope of a window, you can try to guess your way down to individual elements using commands like:

UI elements of window 1
UI elements of splitter group 1 of window 1
UI elements of group 1 of splitter group 1 of window 1

These will give you a list that you can use to narrow down your search for elements and their respective titles.

share|improve this answer
+100 for letting me know about UIElementInspector – Nifle Oct 15 '11 at 22:29
@slhck - Wow! What a fantastic answer. It is very much appreciated, and I will get to work right away on this. Curious however, as I'm new to AppleScript in general; How would I make the UI elements commands? – stefmikhail Oct 15 '11 at 22:35
@Stef Well, for example UI Elements of window "Authenticate" of process .... Just do this in AppleScript editor and look at the results at the bottom. I unfortunately haven't found a more efficient way to do this though. – slhck Oct 15 '11 at 23:00
@slhck - No no that sounds perfect. And ends up UI Browser offers a one month full feature trial, so I'll be able to give that a go as well. Again, thanks a bunch. – stefmikhail Oct 16 '11 at 0:29
@stefmikhail Sure, no problem! Let me know how UI Browser works for you, haven't had the time yet to try it! – slhck Oct 16 '11 at 8:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .