Last active
July 18, 2024 05:48
-
-
Save yohamta/f1ea6dfe5a79571342e06407cad4f5b3 to your computer and use it in GitHub Desktop.
CloseAllVSCodeWIndows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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