In fundamental vanilla AppleScript there isn’t a property
, component
or class
for a tab in a window in Finder, and as such it makes it troublesome to inform if a window presents with a number of tabs on the UI degree, (a number of home windows
introduced as tabs inside a single UI degree window).
The next instance AppleScript code is a bit kludgy as it might/will reduce and un-minimize the seen entrance UI degree window, nonetheless, is does shut all different home windows
not inside the window that’s frontmost and visual on the UI degree on the time the code is run.
Instance AppleScript code:
inform utility id "com.apple.finder"
if (depend home windows) is lower than or equal to 1 then return
set collapsedWindows to home windows whose collapsed is true
shut collapsedWindows
if (depend home windows) is bigger than 1 then
set collapsed of window 1 to true
set uncollapsedWindows to home windows whose collapsed is fake
shut uncollapsedWindows
set collapsed of window 1 to false
finish if
finish inform
Notes:
What the instance AppleScript code does:
- Checks the variety of
home windows
for error dealing with functions. - Closes all
home windows
which might be at the moment minimized (collapsed:true
). - Then if multiple
window
, minimizes the entrance window. - Closes all
home windows
that aren’t at the moment minimized (collapsed:false
). - Un-minimizes the one remaining window (
home windows
the placecollapsed:true
).
Word that if there is just one window in Finder with a number of tabs and is minimized when the code is run it should shut that window, nonetheless, I take this situation to be exterior the scope of the intent of the query, because the key phrase use within the OP was “energetic” and a minimized window will not be thought-about the “energetic” window in regular context. That is additionally an unlucky consequence of there not being a tab
as a property
, component
or class
for a tab in a window in Finder.
Word that phrases used within the paragraphs above proven as, e.g. window
are referring to them programmatically and proven as e.g. window are referring to them on the UI degree.
The instance AppleScript code, proven above, was examined in Script Editor beneath each model of macOS from macOS Sierra to macOS Monterey with Language & Area settings in System Preferences set to English (US) — Major and labored for me with out problem1.
- 1 Assumes needed and applicable settings in System Preferences > Safety & Privateness > Privateness have been set/addressed as wanted.
Word: The instance AppleScript code is simply that and sans any included error dealing with doesn’t include any further error dealing with as could also be applicable. The onus is upon the person so as to add any error dealing with as could also be applicable, wanted or wished. Take a look on the strive assertion and error assertion within the AppleScript Language Information. See additionally, Working with Errors. Moreover, the usage of the delay command could also be needed between occasions the place applicable, e.g. delay 0.5
, with the worth of the delay set appropriately.