4

I am very, very new to using AppleScript. I need to enter text into the search box. So far the script looks like this:

on run {input, parameters}

    tell application "myApplication" to activate

    tell application "System Events"
        keystroke "o" using {command down}
    end tell

    return input
end run

This launches the app and fires the command-o keyboard shortcut to show a file dialog. Now I just need to enter text in:enter image description here

2
  • What's your actual goal here? Do you need to use the search, or do you just need to find and open a specific file?
    – robmathers
    Sep 12, 2012 at 18:54
  • Well, I need to find and open a folder and get the contents from it.
    – daveMac
    Sep 12, 2012 at 19:00

1 Answer 1

3

The trick is figuring out how to address the correct control item in the window. See this hint for an explanation of how to get the needed information: http://hints.macworld.com/article.php?story=20111208191312748

This Applescript code will work on a Finder window named "Titan":

-- text field 1 of group 5 of tool bar 1 of window "Titan" of application process "Finder" of application "System Events"
-- button 1 of text field 1 of group 5 of tool bar 1 of window "Titan" of application process "Finder" of application "System Events"

set windowname to "Titan"
-- set this to name of open Finder window you want to deal with

tell application "Finder"
    activate
end tell

tell application "System Events"
    tell process "Finder"
        set value of text field 1 of group 5 of tool bar 1 of window windowname to "Here is some text"
    end tell
end tell

Anyway, the code'll insert "here is some text" into the Finder window's search box. The first 2 lines are comments showing the pieces of the search box. You can probably click on that button too.

11
  • I am not sure how to implement this. Copy and paste doesn't work. Any tips?
    – daveMac
    Sep 13, 2012 at 17:13
  • I've reformmatted the code snippet with line-feeds. That should help. At least it's readable now. Sep 13, 2012 at 17:34
  • @WayfaringStranger I redid the code formatting so it looks right.
    – Cajunluke
    Sep 13, 2012 at 17:41
  • @daveMac Copy-and-pasting should work now.
    – Cajunluke
    Sep 13, 2012 at 17:42
  • 1
    'Titan' is just the name of whatever Finder window you have open. If you don't want to use the window's name, you could always direct the command to the FRONTmost Finder window by telling the Finder: set value of text field 1 of group 5 of tool bar 1 of front window to "Here is some text" Sep 13, 2012 at 20:17

You must log in to answer this question.

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