Smart Web Page Opening with FastScripts

March 3rd, 2023

FastScripts, our macOS scripting utility, facilitates organizing and running your scripts from its menu bar icon, or by keyboard shortcut. It serves many roles as a script runner, but also includes a number of built-in features that augment the baseline features available to AppleScript scripts.

One of those useful features is the open web page command, which abstracts the surprisingly complex notion of “navigating to a given web page URL in your current browser, or default browser” to a simple command you can invoke from any script.

The basic idea is: given a URL you’d like to visit, how do we open it in an appropriate browser, creating a new window if necessary, or replacing the current page when appropriate? FastScripts builds a lot of common sense into its handling of the open web page command, so that for example, if you configure a FastScripts script called “Google News”:

tell application "FastScripts"
   open web page ""
end tell

It will open the web page by instructing a web browser on your Mac to open the URL. First, it identifies the ideal browser to open the URL in, based on the following criteria:

  1. The frontmost app, if it’s a known browser
  2. Your default browser, if it is running
  3. Any known browser, if it is running
  4. Launching your default browser, if configured
  5. Launching any known browser on your system

The long and short of this is you can use FastScripts’s “open web page” command to create scripts that open web pages intelligently. That intelligence goes farther than just choosing which browser to open the link in. Where possible, FastScripts also decides whether to create a new window or tab. By default it favors replacing the current page in the current browser.

I use this command extensively in my own collection of “Frequent Web Pages”. I configure these to have the same app-specific keyboard shortcuts in Safari, Brave, Chrome, Firefox, and any other browser I might be using at any time. That way when I press Ctrl-N, for example, in a browser, it always takes me to Google News.

If your scripts ever call for opening web pages in either the current browser or your default browser, I’m sure you’ll enjoy the functionality of FastScripts’s open web page command.