From 4af32a48e59a43e83b8075bea038d47c31932b0e Mon Sep 17 00:00:00 2001 From: Daniel Romischer Date: Thu, 29 Jan 2026 10:12:19 -0500 Subject: [PATCH] even better now great stuff --- SpyderScripts/minimize_all.py | 94 +++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/SpyderScripts/minimize_all.py b/SpyderScripts/minimize_all.py index 9b5a3b4..85c2ebd 100644 --- a/SpyderScripts/minimize_all.py +++ b/SpyderScripts/minimize_all.py @@ -68,6 +68,54 @@ def minimize_window_via_applescript(app_name): return False +# Apps that don't respond to Cmd+M and need special handling +# Maps app display name -> process name (as seen by System Events) +EXCEPTION_APPS = { + 'Spyder 6': 'python', + 'MacVim': 'MacVim', + # Add more exception apps here as needed, e.g.: + # 'SomeApp': 'some_process_name', +} + + +def minimize_exception_app(app_name, process_name): + """ + Minimize windows for apps that don't respond to Cmd+M. + Uses the AXMinimized accessibility attribute directly. + """ + script = f''' + tell application "System Events" + tell process "{process_name}" + set windowCount to count of windows + if windowCount > 0 then + repeat with w in windows + try + -- Only minimize if not already minimized + if value of attribute "AXMinimized" of w is false then + set value of attribute "AXMinimized" of w to true + end if + end try + end repeat + end if + return windowCount + end tell + end tell + ''' + try: + result = subprocess.run( + ['osascript', '-e', script], + capture_output=True, + text=True, + timeout=10 + ) + window_count = result.stdout.strip() + print(f"{app_name}: Minimized via AXMinimized (windows: {window_count})") + return True + except Exception as e: + print(f"Failed to minimize {app_name} via AXMinimized: {e}") + return False + + def minimize_finder_windows(): """Minimize all Finder windows using Finder's native scripting""" # First, get count of non-collapsed Finder windows @@ -121,6 +169,10 @@ def main(): # Remove Finder from the set - we'll handle it specially apps_with_windows.discard('Finder') + # Also remove exception apps from the main loop - we'll handle them separately + for exception_app in EXCEPTION_APPS.keys(): + apps_with_windows.discard(exception_app) + # Get all running applications (to get proper app objects) workspace = NSWorkspace.sharedWorkspace() running_apps = workspace.runningApplications() @@ -138,6 +190,10 @@ def main(): if app_name not in apps_with_windows: continue + # Skip exception apps - they're handled separately + if app_name in EXCEPTION_APPS: + continue + # Skip system apps and problematic apps if app_name in skip_apps: continue @@ -155,6 +211,44 @@ def main(): processed_apps.add(app_name) time.sleep(0.3) + # Handle exception apps that don't respond to Cmd+M + for app_name, process_name in EXCEPTION_APPS.items(): + # Check if this app actually has visible windows + # We need to re-check since we removed it from apps_with_windows earlier + check_script = f''' + tell application "System Events" + if exists process "{process_name}" then + tell process "{process_name}" + set visibleCount to 0 + repeat with w in windows + try + if value of attribute "AXMinimized" of w is false then + set visibleCount to visibleCount + 1 + end if + end try + end repeat + return visibleCount + end tell + else + return 0 + end if + end tell + ''' + try: + result = subprocess.run( + ['osascript', '-e', check_script], + capture_output=True, + text=True, + timeout=5 + ) + visible_count = int(result.stdout.strip()) if result.stdout.strip() else 0 + if visible_count > 0: + print(f"Processing exception app: {app_name}") + minimize_exception_app(app_name, process_name) + time.sleep(0.3) + except Exception as e: + print(f"Error checking {app_name}: {e}") + # FIX #2: Handle Finder windows separately using Finder's native scripting # This is more reliable than using Cmd+M minimize_finder_windows()