Wednesday, February 01, 2023

AppleScript that opens a given URL in the command line on a Chrome browser

Here is an example AppleScript that opens a given URL in the Chrome browser:


on run argv

  set url_string to item 1 of argv

  tell application "Google Chrome"

    activate

    open location url_string

  end tell

end run


You can save this script as an application and run it from the command line by passing in the URL as an argument. For example:


osascript /path/to/script.scpt "https://www.example.com"


This script activates the Chrome browser and opens the specified URL in a new tab.