Is it possible to use AppleScript to open a link in a new tab 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.
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.
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
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'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With