Skip to content

Instantly share code, notes, and snippets.

@jamesstout
Last active December 19, 2015 17:19
Show Gist options
  • Save jamesstout/5990388 to your computer and use it in GitHub Desktop.
Save jamesstout/5990388 to your computer and use it in GitHub Desktop.
Improved AppleScript to close all Finder Get Info windows
tell application "Finder"
set theWindowList to windows (* get all Finder windows *)
repeat with i from 1 to number of items in theWindowList (* loop through them *)
set shouldClose to false (* reset to false *)
set this_item to item i of theWindowList (* get a window from the list *)
set windowName to name of this_item (* get the window'ss name *)
(* this list should contain class property that tells you the type of window - which is nice *)
(* Class would be either "Finder window" for normal windows or "information window" for the Info windows *)
(* However, it doesn't contain the class property. alas. *)
(* So to differentiate, we can use the current view/panel props *)
set thePropList to get properties of this_item
(* in a try/catch as prop not set for the diff windows *)
try
set CurrentView to current panel of thePropList
set shouldClose to true (* no error, it's an info panel, so close *)
on error
log "Not an info panel, leaving open: " & windowName
end try
(* this try/catch is just for a double check, feel free to comment out *)
try
set CurrentView to current view of thePropList
on error
if shouldClose = false then log "Not an info panel: " & windowName
end try
if windowName ends with " Info" and shouldClose then
close this_item
log "Closing info panel: " & windowName
end if
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment