I want to open an URL in a browser's private mode.
--args -incognito
does the job with Chromium-based browsers (e.g. open -na "Google Chrome" --args -incognito http://www.example.com
).
I tried -incognito
, -private
, -private-browsing
arguments, but none worked with Safari.
What's a Safari's command option to open in private mode?
MacOS – Open an URL in Safari with Private Browsing
command linemacossafari
Related Question
- IOS – (How) Can a web site determine if Safari Private Browsing is turned on
- MacOS – Safari address bar complete URL with keyboard shortcut
- MacOS – Keep sessions between private tabs
- MacOS – Safari – Easy way to open a link in private window
- IOS – Is Safari, in incognito mode, saving its settings
- MacOS – How to preserve session in Safari private window mode
- Safari doesn’t detect font installed on system
- Dump dom of url from command line with safari
Best Answer
Safari does not have similar command line options like Google Chrome, however, here is a way to roll your own:
In Terminal, run the following compound command:
Copy and paste the example AppleScript code, shown further below, into the opened safari document, then save it.
You should then move the
safari
shell script to a directory located within the shell'sPATH
.I moved it to
/usr/local/bin
, e.g,:Now from Terminal I can open a new private window for Safari.
Typing just the executable's name without any arguments shows how it can be used e.g,:
Notes:
Example AppleScript code: