AppleScript for launching Safari on macOS in Private Mode

Nowadays, we may want to surf permanently the internet in private browsing mode. The following AppleScript activates Safari by closing all empty none-private windows/tabs and finally opens a new private one:

use scripting additions

tell application "Safari"

      set windowCount to number of windows
      repeat with i from windowCount to 1 by -1
            set tabCount to number of tabs in window i
            repeat with j from tabCount to 1 by -1
               set thistab to tab j of window i
               set thisURL to URL of thistab
                  get thisURL
               on error
                  close thistab
               end try
            end repeat
         end try
      end repeat
   end try

   tell application "System Events"
      tell process "Safari"
         keystroke "N" using {shift down, command down}
      end tell
   end tell

   delay 0.25
   set bounds of front window to {2, 24, 1210, 797} as bounding rectangle

end tell

You might want to save this in „Application“ format by using the Script-Editor. Then open the app bundle and add the following 2 lines to contents/info.plist:


Copyright © Dr. Rolf Jansen - 2019-01-24 19:46:51

Discussion on Twitter: 1088555422729019393