Applescript Studio Selecting contents of text field

Discussion in 'Mac Programming' started by lynkynpark86, Mar 18, 2010.

  1. lynkynpark86 macrumors 6502

    I am making a browser, and I am adding a search bar to it. I am making it set the contents of the search bar to a variable, then setting the contents of the URL bar to "" and then the variable with the search terms. And it works fine, but I cannot get it to automatically submit the URL to the web view. So I want to add to my script to select (highlight) the contents of the URL bar, then keystroke return to submit the URL. Does anyone know how to select the contents of the text field in my nib file using applescript? Please Help! :apple:
  2. silent2532 macrumors newbie

    Mar 19, 2010
    tell application "System Events"
    tell process "Your App"
    keydown command
    keystroke c
    keyup command
    tell application "Your App"
    end tell
    keydown command
    keystroke v
    keyup command
    keystroke return
    end tell
    end tell

    Something like that?
  3. lynkynpark86 thread starter macrumors 6502

    Not Quite...

    That doesn't quite work for that, I just want it to highlight the text in the text field. Something like:
    tell window "Main Window"
       set searchTerms to the contents of text field "searchBar"
       set contents of text field "URLBar" to "" & searchTerms
       select contents of text field "URLBar"
       tell application "system events"
          tell process "MyApp"
             keystroke return
          end tell
       end tell
    end tell
    except the "select contents of text field 'URLBar' " doesn't work. I want it to highlight all the text it the text field "URLBar", but it gives me an error. It changes the text in the url bar fine, just wont highlight. Thanks.

Share This Page