Hide All / Show Desktop applescript

I have been trying to get together a script that will hide all windows and simply show the desktop. I know expose can do a similar thing, as can CMD-OPT clicking desktop but they aren’t the same as a proper ‘hide all / show desktop’. Besides, it doesn’t sound too hard. Here’s what I have so far.

tell application "System Events"
	set visible of (every process whose visible is true and frontmost is false) to false
	set visible of process "Finder" to false
end tell

When I run it from within script editor, it seems to work perfectly, but when I try and run it from the scripts menu, or the fastscripts menu it just doesn’t work. It will always leave 1 application or window visible.

Can anyone help me out?

This seems to work:

activate application "Finder"
tell application "System Events" to keystroke "h" using {command down, option down}

If you want to close any open Finder windows, you could use this instead:

tell application "Finder"
	activate
	close every window
end tell

tell application "System Events" to keystroke "h" using {command down, option down}

ok, so that hides everything except finder windows, so it mirrors what CMD-OPT-CLICK on desktop does.

and that hides everything, great! thanks. It does seem to stutter a bit though I notice, like it brings the finder window to the front and then hides them.

Also, when using fastscripts menu to assign a shortcut key to it, sometimes I have to press the shortcut twice for it to work.

Has anyone tried running this script with a shortcut key? please try.