Skip to content

Instantly share code, notes, and snippets.

@yohamta
Last active July 18, 2024 05:48
Show Gist options
  • Save yohamta/f1ea6dfe5a79571342e06407cad4f5b3 to your computer and use it in GitHub Desktop.
Save yohamta/f1ea6dfe5a79571342e06407cad4f5b3 to your computer and use it in GitHub Desktop.
CloseAllVSCodeWIndows
use scripting additions
on run
set maxAttempts to 5
set attemptCount to 0
repeat
set attemptCount to attemptCount + 1
try
tell application "System Events"
if application process "Code" exists then
tell application process "Code"
set frontmost to true
delay 0.5
keystroke "w" using {shift down, command down}
delay 0.5
end tell
else
exit repeat
end if
end tell
on error errMsg
display dialog "Error: " & errMsg buttons {"OK"} default button "OK"
exit repeat
end try
-- Check if VS Code is still running
try
tell application "System Events"
if not (exists application process "Code") then
exit repeat
end if
end tell
end try
if attemptCount maxAttempts then
exit repeat
end if
end repeat
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment