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'm running OS X 10.6 and I want to use applescript to click on the "File Name" radio button of the finder window when the search is open. (It defaults to "Contents")

I used the UI Browser (below) and came up with a path, but Applescript is giving me some errors so I must be doing something wrong. I've posted my code and screen shots below:


tell application "System Events"
    activate application "Finder"
    click checkbox "File Name" of radio group 1 of group 1 of splitter group 1 of window 1 of application "Finder"
end tell

Screen Cap:

enter image description here

Code From UIElementInspector

<AXApplication: “Finder”>
 <AXWindow: “Searching “UIElementInspector””>
     <AXCheckBox: “File Name”>

   AXRole:  “AXCheckBox”
   AXRoleDescription:  “check box”
   AXHelp:  “(null)”
   AXValue:  “1”
   AXEnabled:  “1”
   AXFocused (W):  “0”
   AXParent:  “<AXRadioGroup>”
   AXWindow:  “<AXWindow: “Searching “UIElementInspector””>”
   AXTopLevelUIElement:  “<AXWindow: “Searching “UIElementInspector””>”
   AXPosition:  “x=1357 y=149”
   AXSize:  “w=75 h=17”
   AXTitle:  “File Name”

   AXPress - press
share|improve this question
up vote 1 down vote accepted

Some more retarded UI scripting:

tell application "System Events" to tell process "Finder"
    set frontmost to true
    click menu bar 1's menu bar item "File"'s menu 1's menu item "Find"
    tell application "Finder"
        set toolbar visible of window 1 to false
        set bounds of window 1 to {0, 22, 960, 587}
    end tell
    tell window 1's splitter group 1
        click group 1's radio group 2's checkbox "File Name"
        click group 1's radio group 1's radio button "This Mac"
        click scroll area 1's outline 1's group 1's button 1 -- sort by Name
        click group 2's pop up button 1
        keystroke "sys" & return
        click group 2's pop up button 2
        keystroke "are " & return
    end tell
end tell

For some reason, on my 10.6.7 checkbox "File Name" is in radio group 2 instead of radio group 1.

share|improve this answer
Thanks! This did what I wanted it to, (actually a lot more than I wanted it to!) and it was very easy to just drop this in and start using it, so I'm going to mark it as the correct answer. Thanks! – cwd Mar 31 '11 at 16:11
@cwd Yeah, I just added the extra stuff as examples of GUI scripting. – user495470 Mar 31 '11 at 17:06

Scripted UI operations can't be communicated to applications directly; they must go to an application process, in this case application process "Finder" as distinct from application "Finder". More information

BTW, Apple has sample code to do that exploration, instead of using a trial commercial program that may eventually time out or cease working.

share|improve this answer
Could you give an example of the syntax I would use to do the first part of your suggestion? – cwd Mar 29 '11 at 20:51
Just replacing application "Finder" with application process "Finder" should work, although it might be necessary to get a more direct handle from System Events (tell application "System Events" to set app to first application process whose name is "Finder" or similar). – geekosaur Mar 29 '11 at 20:55
BTW I have a (still in development/debugging) Automator workflow that does quite a lot of UI hacking; see – geekosaur Mar 29 '11 at 21:05
looks like a broken link, but I'd still love to see it. – cwd Mar 29 '11 at 21:38
Sorry, case-o. works. – geekosaur Mar 29 '11 at 21:43

You must log in to answer this question.

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