Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open URL in new Safari tab with AppleScript

Is it possible to use AppleScript to open a link in a new tab in Safari?

like image 489
Mark Szymanski Avatar asked May 23 '10 17:05

Mark Szymanski


People also ask

How do I run AppleScript in Safari?

Safari won't automatically run the script on launch. The easiest way to run the script is to place the script in ~/Library/Application Scripts/com. apple. Safari , then you can run the script from the Script menu when Safari is running.

Does Apple still use AppleScript?

AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools.


2 Answers

This will work:

tell application "Safari"     tell window 1         set current tab to (make new tab with properties {URL:"http://www.stackoverflow.com"})     end tell end tell 
like image 198
Tim Lewis Avatar answered Sep 19 '22 08:09

Tim Lewis


I think this also does what you asked for, but it is much shorter and is less browser-specific:

do shell script "open http://www.webpagehere.com" 

This will open the specified URL in your default browser. And if you explicitly want to open it in Safari, use this:

do shell script "open -a Safari 'http://www.webpagehere.com'" 
like image 33
rien333 Avatar answered Sep 22 '22 08:09

rien333