Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lynkynpark86

macrumors 6502
Original poster
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 "http://www.google.com/alltherandomsearchstuff=" 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:
 
tell application "System Events"
tell process "Your App"
keydown command
keystroke c
keyup command
tell application "Your App"
activate
end tell
keydown command
keystroke v
keyup command
keystroke return
end tell
end tell

Something like that?
 
Not Quite...

That doesn't quite work for that, I just want it to highlight the text in the text field. Something like:
Code:
tell window "Main Window"
   set searchTerms to the contents of text field "searchBar"
   set contents of text field "URLBar" to "http://www.google.com/search?q=" & 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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.