Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevin-funderburg/6af5ba51385eeca2fd35054d23114d04 to your computer and use it in GitHub Desktop.
Save kevin-funderburg/6af5ba51385eeca2fd35054d23114d04 to your computer and use it in GitHub Desktop.
Closes all the un-saved documents of the front app.
-- 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