Skip to content

Instantly share code, notes, and snippets.

@mistadikay
Created August 7, 2017 20:54
Show Gist options
  • Save mistadikay/844ca188e3b6d3db1d629825715c25fe to your computer and use it in GitHub Desktop.
Save mistadikay/844ca188e3b6d3db1d629825715c25fe to your computer and use it in GitHub Desktop.
Run this script on Cmd + W to prevent closing the last tab in Safari
tell application "Safari"
set numWin to count of tabs of window 1
if numWin > 1 then
close current tab of front window
end if
if numWin = 1 then
tell application "Safari" to activate
tell application "System Events"
keystroke "t" using command down
end tell
tell window 1 of application "Safari"
close (tabs where index < (get index of current tab))
end tell
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment