Opening URLs in Private Safari 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.
I’ve set PrivateWindow as the browser associated with certain logins in PasswordWallet. Among other benefits, this means I can download a financial statement and then “log out” simply by closing the tab.
Since Apple doesn’t provide any API for this, the apps use AppleScript to automatically click menu items in the Safari File menu in the main menu bar, a primitive but effective method. Or mostly effective. It turns out that this method didn’t support Safari Profiles, which add items to the Safari File menu. The shortcoming has been rectified in version 2.0 of PrivateWindow and PublicWindow.
Apple should add a real AppleScript API so that this sort of thing can be done without GUI scripting. You should be able to directly specify whether a URL should be opened in a private or public window and which profile should be used. Really, it should also be available at the Launch Services level. Currently, there’s a standard way to specify whether an application should open a URL in the background or whether a file should not be added to the recents. Private browsing should be in there, too.