macos – Apple Script to shut all home windows in Finder — however maintain lively window AND ITS TABS open?

0
17
macos – Apple Script to shut all home windows in Finder — however maintain lively window AND ITS TABS open?


In primary vanilla AppleScript there isn’t any property, aspect 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 offered as tabs inside a single UI degree window).

The next instance AppleScript code is a bit kludgy as it will possibly/will reduce and un-minimize the seen entrance UI degree window, nevertheless, 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 (rely home windows) is lower than or equal to 1 then return
    set collapsedWindows to home windows whose collapsed is true
    shut collapsedWindows
    if (rely home windows) is larger 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 are presently minimized (collapsed:true).
  • Then if a couple of window, minimizes the entrance window.
  • Closes all home windows that aren’t presently minimized (collapsed:false).
  • Un-minimizes the one remaining window (home windows the place collapsed: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 is going to shut that window, nevertheless, I take this situation to be outdoors the scope of the intent of the query, because the key phrase use within the OP was “lively” and a minimized window just isn’t thought of the “lively” window in regular context. That is additionally an unlucky consequence of there not being a tab as a property, aspect 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 underneath each model of macOS from macOS Sierra to macOS Monterey with Language & Area settings in System Preferences set to English (US) — Main and labored for me with out situation1.

  • 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 needed. Take a look on the attempt 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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here