Created
May 15, 2019 21:49
-
-
Save kevin-funderburg/6af5ba51385eeca2fd35054d23114d04 to your computer and use it in GitHub Desktop.
Closes all the un-saved documents of the front app.
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
-- Note: This works in all the apps I’ve tried it in, so there may be others it doesn't | |
tell application "System Events" to set frontapp to name of first process whose frontmost is true | |
tell application frontapp | |
activate | |
repeat with i from (count of documents) to 1 by -1 | |
set thisDocument to document i | |
try | |
if path of (get properties of thisDocument) = missing value or name of thisDocument contains "Untitled" then | |
close thisDocument without saving | |
end if | |
on error errMsg number errNum | |
display alert "Error" message errMsg as critical buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel" | |
end try | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment