A friend of mine asked how to minimize all windows in all open applications. This is what I came up with. The script only works if 'Enable access for assistive devices' is checked in the Universal Access System Preferences panel.
tell application "System Events"
set theButtons to {}
repeat with theApplication in application processes
repeat with theWindow in windows of theApplication
repeat with theButton in buttons of theWindow
if ((description of theButton) is "minimize button") then
set theButtons to theButtons & {theButton}
end if
end repeat
end repeat
end repeat
repeat with theButton in theButtons
click theButton
end repeat
--do it twice because it usually misses one the first time
repeat with theButton in theButtons
click theButton
end repeat
end tell
[robg adds: On my desktop Mac, this script didn't seem to work at all -- it just sent CPU utilization to near maximum and sat there. (It worked fine on my PowerBook.) Investigating further, I figured out that when jEdit (a text editor written in Java) was running, then the script would hang. When I quit jEdit, the script worked as described. I'm not sure if this is a general problem with Java apps, or something specific to jEdit. Unfortunately, there's no "expand all minimized windows" alternative, though option-clicking on a window in the Dock should expand all of that application's other docked windows.]
Mac OS X Hints
http://hints.macworld.com/article.php?story=20060228103054894