Sunday, November 29, 2020

#1 2018-12-01 06:14:36 pm

Eurobubba
Member
Registered: 2010-09-06
Posts: 7

AS counts Finder window tabs as windows in Mojave

If I have one Finder window with two tabs open in High Sierra, the script below will return 1:

Applescript:

tell application "Finder" to count windows

In Mojave it returns 2 — but it won't split the tabs into separate windows if I manipulate their bounds separately. Which means my trusty old dual window script is now broken. And the Finder dictionary still doesn't contain a tab object as such. Does anyone know how to get a count of windows as distinct from tabs in Mojave?

Browser: Safari 605.1.15
Operating System: macOS 10.14


Filed under: Finder, windows, tabs

Offline

 

#2 2019-02-01 12:51:15 pm

wch1zpink
Member
Registered: 2011-08-20
Posts: 3

Re: AS counts Finder window tabs as windows in Mojave

Here is a little work around that may work for you.  This code will return the total tab count of all tabs in every finder window combined.  It will also return the number of open finder windows, and will return the name of the active tab in each finder window.

Applescript:


global tabCountRef, totalTabs, windowNames, totalWindows

totalWindowCount()

on totalWindowCount()
   tell application "Finder"
       activate
       repeat until application "Finder" is frontmost
           delay 0.1
       end repeat
   end tell
   tell application "System Events"
       repeat until radio buttons of tab group 1 of window 1 of application process "Finder" exists
           delay 0.1
       end repeat
       set tabCountRef to a reference to radio buttons of tab groups of windows of application process "Finder"
       set totalTabs to count of tabCountRef
       set windowNames to name of windows of application process "Finder"
       set totalWindows to count of windowNames
   end tell
end totalWindowCount

Offline

 

#3 2020-11-20 09:57:25 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: AS counts Finder window tabs as windows in Mojave

Here, I wrote solution, which doesn't use GUI scripting. The script returns "real" Finder windows count instead of count tabs as windows. Open some windows with multiple tabs in each of them to test:

Applescript:


-- script: counts "real" Finder windows instead of counting tabs as windows

set uniqueBoundsList to {}
set realWindowsCount to 0

tell application "Finder"
   repeat with FinderWindow in (get every Finder window)
       set theBounds to bounds of FinderWindow
       if not (uniqueBoundsList contains {theBounds}) then
           set end of uniqueBoundsList to theBounds
           set realWindowsCount to realWindowsCount + 1
       end if
   end repeat
end tell

return realWindowsCount


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)