System-wide shortcut to open a new window in Safari

automatormojavesafari

I'm trying to use Automator to create a system-wide shortcut to open a new Safari window. I'm using the method described in this answer.

I can get Safari to open a specific url, for example by running

$ open -a Safari "https://apple.stackexchange.com"

From the command line. But this opens a new tab (not a new window) and requires specifying a URL.

Automator also has an "Internet > Display Webpages" action that has the same problems.

enter image description here

Is there a way to get Safari to open a new, blank window?

Best Answer

In Automator, create a Service workflow (pre macOS Mojave), or a Quick Action workflow in macOS Mojave.

Add a Run AppleScript action, replacing the default code, with:

tell application "Safari" to make new document

The above piece of AppleScript code by itself will open a new window in Safari however, it will not have focus. If you want the new window to have focus then use a tell block, e.g.:

tell application "Safari"
    make new document
    activate
end tell

You can then assign a keyboard shortcut in the usual manner per information in the link within your question.