more playing around spyder scripts

let's bounce.
This commit is contained in:
2026-01-28 19:20:23 -05:00
parent 211f403dbc
commit aecaa39609
5 changed files with 186 additions and 0 deletions

BIN
SpyderScripts/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,100 @@
#!/usr/bin/env python3
"""
Minimize All Windows - Python Version
Requires: pip3 install pyobjc-framework-Cocoa pyobjc-framework-Quartz
This uses native macOS APIs which should be more reliable than AppleScript.
"""
import time
from Cocoa import NSWorkspace, NSRunningApplication
from Quartz import (
CGWindowListCopyWindowInfo,
kCGWindowListOptionOnScreenOnly,
kCGNullWindowID
)
import subprocess
def get_all_windows():
"""Get all visible windows from all apps"""
window_list = CGWindowListCopyWindowInfo(
kCGWindowListOptionOnScreenOnly,
kCGNullWindowID
)
return window_list
def minimize_window_via_applescript(app_name):
"""Use AppleScript to minimize the frontmost window of an app"""
script = f'''
tell application "{app_name}"
activate
end tell
delay 0.8
tell application "System Events"
tell process "{app_name}"
set frontmost to true
delay 0.4
keystroke "m" using command down
end tell
end tell
'''
try:
subprocess.run(['osascript', '-e', script], timeout=5, check=False)
return True
except Exception as e:
print(f"Failed to minimize {app_name}: {e}")
return False
def main():
# Apps to skip
skip_apps = {'Finder', 'SystemUIServer', 'Dock', 'Electron', 'MSTeams', 'nxdock'}
skip_keywords = ['Helper', 'Agent']
# Get all running applications
workspace = NSWorkspace.sharedWorkspace()
running_apps = workspace.runningApplications()
processed_apps = set()
for app in running_apps:
app_name = app.localizedName()
# Skip if already processed
if app_name in processed_apps:
continue
# Skip system apps and problematic apps
if app_name in skip_apps:
continue
# Skip apps with certain keywords
if any(keyword in app_name for keyword in skip_keywords):
continue
# Skip if not a regular app
if not app.activationPolicy() == 0: # NSApplicationActivationPolicyRegular
continue
print(f"Processing: {app_name}")
minimize_window_via_applescript(app_name)
processed_apps.add(app_name)
time.sleep(0.3)
# Handle Finder windows separately
print("Processing: Finder windows")
finder_script = '''
tell application "Finder"
try
set allWindows to every Finder window
repeat with aWindow in allWindows
set miniaturized of aWindow to true
end repeat
end try
end tell
'''
subprocess.run(['osascript', '-e', finder_script], check=False)
print("Done minimizing all windows")
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,54 @@
#!/bin/bash
# Minimize All Windows - Simplified and Improved
osascript <<EOF
tell application "System Events"
set allApps to name of (every process whose visible is true)
end tell
repeat with appName in allApps
-- Skip problematic apps
if appName is not in {"Finder", "SystemUIServer", "Dock", "Electron", "MSTeams", "nxdock"} and ¬
appName does not contain "Helper" and ¬
appName does not contain "Agent" then
try
-- Activate the app
tell application appName
activate
end tell
delay 1.0
-- Make sure it's frontmost and send keystroke
tell application "System Events"
tell process appName
try
-- Ensure the process is frontmost
set frontmost to true
delay 0.3
-- Send Command+M to minimize the frontmost window
keystroke "m" using command down
end try
end tell
end tell
delay 0.3
on error
-- Skip apps that cause errors
end try
end if
end repeat
-- Handle Finder windows
tell application "Finder"
try
set allWindows to every Finder window
repeat with aWindow in allWindows
set miniaturized of aWindow to true
end repeat
end try
end tell
EOF
echo "Done minimizing all windows"

32
SpyderScripts/run_script.zsh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/zsh
# Script to execute an AppleScript or action script file
# Usage: ./run_script.zsh /path/to/your/script.scpt
# Check if a script path was provided
if [ $# -eq 0 ]; then
echo "Error: No script file specified"
echo "Usage: $0 /path/to/script.scpt"
exit 1
fi
SCRIPT_PATH="$1"
# Check if the file exists
if [ ! -f "$SCRIPT_PATH" ]; then
echo "Error: Script file not found: $SCRIPT_PATH"
exit 1
fi
# Execute the script using osascript
osascript "$SCRIPT_PATH"
# Capture the exit status
EXIT_STATUS=$?
if [ $EXIT_STATUS -ne 0 ]; then
echo "Script execution failed with status: $EXIT_STATUS"
exit $EXIT_STATUS
fi
echo "Script executed successfully"