I made this AppleScript to use with the script tool. It can be saved as the application to launch from a click. I have to approve the application though in the Security edit tool.
This open the private browser by clicking the menu items. Then it closes the first window by looking for the unthinkable URL in the Window menu. It is working but flashy as the windows pop open and close.
I wish it can be improved by some way to allow clicking the shortcut then see that only the Safari window is launched in private mode without so much "macro" like appearance. Can you help improve this for me?
# Start or bring forward Safari window
tell application "Safari"
activate
end tell
# Open a URL that cannot be found
set theURL to "http://localhost:38"
tell application "System Events"
tell process "Safari"
open location theURL
end tell
end tell
# Launch a new private window
tell application "System Events"
tell process "Safari"
tell menu bar 1
click menu bar item "File"
tell menu "File"
click menu item "New Private Window"
end tell
end tell
end tell
end tell
# Close the first launcher window
tell application "System Events"
tell process "Safari"
tell menu bar 1
click menu bar item "Window"
tell menu "Window"
click menu item "Failed to open page"
end tell
end tell
tell menu bar 1
click menu bar item "File"
tell menu "File"
click menu item "Close Window"
end tell
end tell
end tell
end tell