1

How do i make applescript type certain things such as urls into the url bar? I've been trying to set up my computers so I don't take 9 years to set everything up when I need to work. I have most of it ready but I can't figure this part out... Can someone help me?

  • 2
    What Browser are you using? – user3439894 Oct 17 '18 at 1:25
  • 1
    Does it have to be AppleScript? You can use open https://google.com from command line directly – Mateusz Szlosek Oct 17 '18 at 9:16
  • I use Google Chrome. – user306533 Oct 31 '18 at 21:30
1

This works with following AppleScript lines:

tell application "Safari"
open location "https://google.ch"
activate
end tell
0

In my case browser, Safari, I do the following: 1. Set Safari to open new windows with favorite

Now when you launched Safari or when you write an AppleScript to activate Safari.app, Safari opens with URL box ready. From then you can just type in your desired URL.

My example script below will open a new tab by pressing Command+T (key code 17), then started typing in "google.com"

tell application "Safari" to activate
tell application "System Events"
    key code 17 using command down
    keystroke "google.com

If your computer is slower, you may find adding delays (denoted in seconds) between command lines helpful:

tell application "Safari" to activate
tell application "System Events"
    delay 0.5
    key code 17 using command down
    delay 0.1
    keystroke "google.com
  • Probably the worst possible way to achieve the end goal that one could ever imagine. But I do like how nicely formatted your answer is. It's very clear and easy to read. – CJK Oct 20 '18 at 10:34
  • Oh thank you for your comment. I’m pretty noob and so I just spontaneously answered this thread without revising or researching based on how I “naturally” achieve this ie by openning new tab with keyboard shortcut and typing in the URL. I even forgot to end tell and whatsoever lol. This has cheered me up. – artnoi Oct 22 '18 at 10:38

You must log in to answer this question.

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