Imagine the following task:
“Use a script to open https://www.example.com/ in Private Browsing mode.”
Well, this does not seem to be a overly sophisticated requirement and should be a rather easy task to implement. For most browsers, that’s absolutely true.
Microsoft Internet Explorer
1 | iexplore.exe -private https://www.example.com/ |
Google Chrome
1 | chrome -incognito https://www.example.com/ |
Mozilla Firefox
1 | firefox -private-window https://www.example.com/ |
Apple Safari
- Go to “System Preferences -> Security & Privacy -> Privacy -> Accessibility”
- Click “Add”, select “Applications -> Utilities -> Terminal”
- Just execute this simple command…
1 | osascript -e 'tell application "Safari" to activate |
In a nutshell, this AppleScript launches Safari and closes the first browser window, which is non-private, right away. Then it uses OSX accessibility features to click through the menu bar to launch a Private Window. Finally it sets the address of the focused window to the desired URL.
Well… praise Apple for making intuitive software that just works. Magical. </rant>