Can someone with Applescript knowledge please tell me why this script does not work and suggest a fix. I copied it from part of a longer script I found on the internet to enable private browsing automatically when Safari is launched. After it launches Safari, the script crashes before private browsing is enabled so I assume the error occurs at that step.
-- Sets Private Browsing
-- Also automatically dismisses the pop-up information window
on run {}
activate application "Safari"
tell application "System Events" to tell application process "Safari"
click menu item "Private Browsing" of menu 1 of menu bar item "Safari" of menu bar 1
click button "OK" of window 1
end tell
end run
-- Sets Private Browsing
-- Also automatically dismisses the pop-up information window
on run {}
activate application "Safari"
tell application "System Events" to tell application process "Safari"
click menu item "Private Browsing" of menu 1 of menu bar item "Safari" of menu bar 1
click button "OK" of window 1
end tell
end run