You can do so by using the Applescript below. You'll need CornerClick and you can find more info on MacWorld.
tell application "System Events"
keystroke "m" using command down
key down shift
delay 0.3
key up shift
end tell
tell application "System Events"
set proc to name of the first process whose frontmost is true
tell process proc
-- add error trapping here
tell its window 1
set w to its name
if get value of attribute "AXMinimized" is false then
tell application "System Events"
keystroke "m" using command down
key down shift
delay 0.3
key up shift
end tell
end if
end tell
--
end tell
end tell
say "Collapse" using "Alex"