If I have one Finder window with two tabs open in High Sierra, the script below will return 1:
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
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.
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
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:
-- 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