What you want, I believe, is actually to minimize all other windows, not hide them. There isn't a truly simple way to do this that I know of, but the simplest way IMO would be to call an applescript that would go through each window of each app and issue the cmd-m command. If minimize is implemented by all of the apps then it should work fine (you could choose to close those that don't minimize if you wanted to). It may take a bit of tinkering to get working exactly right, but the script below, taken from macscripter.net, works 80% of the time for me:
tell application "System Events"
set currentProcesses to name of every application process whose visible = true
end tell
set tmpWindows to 0
repeat with tmpProcess in currentProcesses
tell application tmpProcess
activate
try
set tmpWindows to count windows
on error
set tmpWindows to 1 --> # of windows to try to force closed if it doesn't 'appear' to have any windows
end try
end tell
if tmpWindows > 0 then
tell application "System Events"
tell application tmpProcess
repeat tmpWindows times
try
keystroke "m" using command down
end try
end repeat
end tell
end tell
end if
set tmpWindows to 0
end repeat
The other option would be to use Cocoa Accessibility API to get the windows of each running app and set the AXMinimized . Be forewarned: It can get pretty sticky! These 2 other stackoverflow questions should help you on the way:
Mac / Cocoa - Getting a list of windows using Accessibility API
Cocoa accessibility API, can I click a window in the background without activating it?