Open URLs in private and non-private Safari windows

November 27, 2023
By Jeff Johnson of Underpass App Company

I prefer to use private browsing in Safari. In fact, my Safari General Settings have Safari open with a new private window. (Dear Apple, why isn't there a private window option in the "New windows open with" popup?) Still, there are some sites where I want to remained logged in permanently, such as Mastodon, so I use non-private windows in those cases. For lack of a better term, let's call them public windows to distinguish from private windows. The problem with using both private and public windows is that when I open a URL in Safari from another app, such as Mail app, or such as my own Link Unshortener, which I use as my default web browser, I can't control where exactly the URL opens. If the frontmost Safari window happens to be private, then the URL will open in a private window, whereas if the frontmost Safari window happens to be public, then the URL will open in a public window. Even worse, if Safari is running but currently has no windows, then the URL will open in a new public window, ignoring my "Safari opens with" setting!

I've come up with a solution to this problem. Actually, two solutions, two new Mac apps, which I've named, with great imagination, PrivateWindow and PublicWindow. PrivateWindow opens URLs in Safari private windows, and PublicWindow opens URLs in Safari public windows. You can set either app as your default web browser in Desktop & Dock System Settings (Dear Apple, why Desktop & Dock???), but the true power of the apps becomes evident when you use them with Link Unshortener and my Safari extension StopTheMadness. Custom Web Rules, shared between Link Unshortener and StopTheMadness, allow you to specify URL patterns to open with other apps.

By default, I have Link Unshortener open URLs with the PrivateWindow app.

Link Unshortener General Preferences

According to my Web Rules, however, Link Unshortener opens Reddit, Hacker News, and Mastodon URLs with the PublicWindow app, because I'm logged in to those sites.

Link Unshortener Web Rules Preferences

This solves my problem of controlling exactly where the URLs open.

PrivateWindow and PublicWindow are free and open source. The source code is posted on GitHub, where I've also posted notarized Mac apps that you can download.

As you may already know, and as you can see in the above screenshots, I am not a designer. I didn't create app icons for PrivateWindow and PublicWindow, and I'm not going to pay to have icons professionally designed for free apps, but I certainly welcome app icon contributions from the audience!

PrivateWindow was originally based on the app Safari Private by Sindre Sorhus. I credit Safari Private here for inspiring several crucial sections of the PrivateWindow source code, and I also credit Safari Private in the PrivateWindow license. Safari Private is a useful app in itself, but I found that it had several limitations for my purposes, which is why I decided to create new apps to work around those limitations. First, of course, is that Safari Private can only open Safari private windows, not Safari public windows. Second, Safari Private doesn't handle opening URLs in the background, for example, from Terminal app:

open -g -a "Safari Private" https://www.apple.com

Unlike PrivateWindow, Safari Private always brings Safari to the front. Third, Safari Private only works with Safari, whereas PrivateWindow works with either Safari or Safari Technology Preview. Fourth, Safari Private doesn't handle opening multiple URLs in succession, for example:

open -a "Safari Private" https://www.apple.com; open -a "Safari Private" https://www.cnn.com

I did submit a pull request for the last issue, but it seemed a bit beyond of the scope of the existing Safari Private app to split it into two separate apps like I ended up doing. In any case, much thanks to Safari Private and Sindre Sorhus!