Reputation: 4841
How can I open a URL on macOS via the command line?
Upvotes: 2
Views: 1933
Reputation: 593
This AppleScript will launch Safari only and bring it to the foreground with the desired URL even when it is not the default browser.
on run argv
launch application "Safari"
delay 1
tell application "Safari"
open location item 1 of argv
end tell
activate application "Safari"
end run
Run it via osascript like this:
osascript safari-open-url.scpt https://someurl.com
Upvotes: 0
Reputation: 165
open location <theUrl>
Is Known by AppleScript and can open the url directly. The default browser will be triggered. No need to invoke Safari explicitly.
Upvotes: 2
Reputation: 4841
I have found two ways to open a URL on macOS via command line
1.
open https://google.com
on run argv
tell application "Safari"
open location item 1 of argv
activate
end tell
end run
osascript open-safari.applescript https://google.com
Upvotes: 2