best working version yet

works for all windows excecpt for spyder it seems.
This commit is contained in:
2026-01-29 09:50:33 -05:00
parent 7db5d72bbd
commit 19b8ef96f5
2 changed files with 8 additions and 9 deletions

View File

@@ -70,10 +70,11 @@ def minimize_window_via_applescript(app_name):
def minimize_finder_windows():
"""Minimize all Finder windows using Finder's native scripting"""
# First, get count of Finder windows to know if we need to do anything
# First, get count of non-collapsed Finder windows
count_script = '''
tell application "Finder"
return count of Finder windows
set visibleWindows to (every Finder window whose collapsed is false)
return count of visibleWindows
end tell
'''
try:
@@ -86,19 +87,17 @@ def minimize_finder_windows():
window_count = int(result.stdout.strip()) if result.stdout.strip() else 0
if window_count == 0:
print("Finder: No windows to minimize")
print("Finder: No visible windows to minimize")
return
print(f"Finder: Minimizing {window_count} window(s)")
# Minimize each window one by one (more reliable than batch)
# Finder uses "collapsed" not "miniaturized" for minimizing windows
minimize_script = '''
tell application "Finder"
repeat with aWindow in (every Finder window)
try
set miniaturized of aWindow to true
delay 0.2
end try
set allWindows to every Finder window
repeat with w in allWindows
set collapsed of w to true
end repeat
end tell
'''