Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A Service to hide/show the Desktop Desktop
Sometimes you have a really cluttered desktop, and you want to clean it off, but you don't have time (or you're just plain lazy). That's where this hint about hiding/showing your desktop via a service comes in.

First of all, open Automator. When you're presented with the options sheet, choose Service. After, in the banner of the action, make it say: 'Service takes no input in any application.'

Now, drag in a Run AppleScript action from the Utilities category. Paste the following text in:
on run {input, parameters}
	set myAnswer to ((do shell script "defaults read com.apple.finder CreateDesktop") as integer) as boolean
	do shell script "defaults write com.apple.finder CreateDesktop " & (((not myAnswer) as integer) as string)
	do shell script "killall Finder"
end run
Finally, save the service as, for example, Hide/Show Desktop. You can assign it a keyboard shortcut, like ⌃⌘H, so you can hide or show your desktop.

Note: this script kills the Finder to finish its job. Remember that if you invoke this during a file operation, bad stuff could happen.

[crarko adds: I tested this, and it works as described.]
    •    
  • Currently 2.38 / 5
  You rated: 3 / 5 (24 votes cast)
 
[9,639 views]  

A Service to hide/show the Desktop | 34 comments | Create New Account
Click here to return to the 'A Service to hide/show the Desktop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A Service to hide/show the Desktop
Authored by: mantrid on Aug 05, '10 07:52:42AM

Since you recognize the danger, rather than using a do shell script to killall Finder harshly, why not tell it first to quit, then activate so that it can do so on its own terms? That way you can avoid the possibility of interrupting a file transfer, etc.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: Coumerelli on Aug 05, '10 08:21:39AM

Some help with that please? :)

---
"The best way to accelerate a PC is 9.8 m/s2"



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: urban_mainframe on Aug 05, '10 08:27:01AM
tell application "Finder" to quit
wait
tell application "Finder" to run


[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: mantrid on Aug 05, '10 09:25:54AM

Yes, "run" is a better choice than "activate" in this context, thanks.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: S Barman on Aug 05, '10 07:53:59AM
This script did not work. When I ran the first defaults on the "set myAnswer..." line:
$ defaults read com.apple.finder CreateDesktop
2010-08-05 10:49:28.967 defaults[7724:903] 
The domain/default pair of (com.apple.finder, CreateDesktop) does not exist
$
Is "CreateDesktop" a property that has to be predefined before running this script?

[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: steve413 on Aug 05, '10 08:22:11AM

It would appear so. Once the default created it works as described and shows up as a variable



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: crarko on Aug 05, '10 08:34:17AM

I didn't need to predefine it, although it's certainly possible that had happened in the process of running some previous script.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: another on Aug 05, '10 08:30:20AM

getting an error message:
error "" number -1721

possibly because of the missing entry?
The domain/default pair of (com.apple.finder, CreateDesktop) does not exist



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: Mackly on Aug 05, '10 08:29:21AM

Isn't that why Apple introduced Spaces? When the desktop gets too cluttered just switch to a new space.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: robertcoogan on Aug 05, '10 09:08:47AM

Good point! I don't know why the writer of the hint doesn't just do that. Why go to all the trouble of writing an Automator action?



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: mantrid on Aug 05, '10 09:24:13AM

All spaces share the same desktop and switching spaces won't make icons on the desktop go away.

This hint turns off the display of the icons on the "Desktop". The "Desktop" background will still be shown, but none of the icons, leading to a much cleaner appearance if your desktop is cluttered. You can still get at your files through a regular Finder window.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: MichaelJ80 on Aug 05, '10 10:54:44PM

I appreciate the input. I struggle with a cluttered desktop more than I care to admit. I will try this and attempt to do a better job of staying on top of it.

---
Michael J Hunter



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: another on Aug 05, '10 08:46:47AM
This hint works perfect, the Key CreateDesktop hides perfectly the Desktop.
but why do I get an error message in my Applescript?

error "" number -1721
Edited on Aug 05, '10 08:48:59AM by another


[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: crarko on Aug 05, '10 09:29:12AM

I think there was a formatting error caused when copying and pasting the script from Geeklog. I've reformatted it slightly and it appears to copy OK now. Give it a try.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: mr. applescript on Aug 05, '10 09:19:00AM
Place the initial query in a try block and if an error occurs because no prefs key is present, create one. Also, tell the Finder to quit instead of killing it:
try
	set myAnswer to ((do shell script "defaults read com.apple.finder CreateDesktop") as integer) as boolean
on error error_message number error_number
	do shell script "defaults write com.apple.finder CreateDesktop 1"
	set myAnswer to true
end try
do shell script "defaults write com.apple.finder CreateDesktop " & (((not myAnswer) as integer) as string)
tell application "Finder" to quit
delay 3
tell application "Finder" to launch


[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: llee on Aug 05, '10 10:43:38AM

This is the one, everybody! Thanks.



[ Reply to This | # ]
One word...
Authored by: slb on Aug 05, '10 10:11:02AM

Camouflage.
Free app that works great.

http://www.macupdate.com/info.php/id/23118/camouflage



[ Reply to This | # ]
One word...
Authored by: ozcaveboy on Aug 05, '10 04:23:40PM

Ditto. Been using Camouflage for years and can't imagine not having it. It can be configured to toggle with nearly any hot key combination you choose.



[ Reply to This | # ]
One word...
Authored by: soundsgoodtome on Aug 19, '10 01:36:24PM

exactly. why do some people insist on doing things the hard way? :-)

i understand tinkering is fun, but when there are so many caveats (such as all this discussion of quitting the finder, etc.), what's the point?



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: nperry on Aug 05, '10 01:14:39PM

The following script will do the same without killing the Finder:

tell application "Finder"
	if visible of window of desktop then
		set the collapsed of window of desktop to true
	else
		open the window of the desktop
	end if
end tell

Note: I observe that sometimes the open is less than instant, other times it is, YMMV.

For the curious: you can test but not set the visible, you can open but not close, and setting collapsed to false fails as collapsing sets visible to false which you can't set... Hence the use of visible, collapsed and open!



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: renaultssoftware on Aug 05, '10 02:06:10PM

Sorry, the hint meant "moving all your icons into la-la land" not "poofing every window into oblivion"

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: nperry on Aug 05, '10 03:11:30PM

Does it not work for you?

I have it installed as a Service and can call it when the Finder or another application is frontmost. If the desktop icons are visible they get "sucked" into the Dock leaving the desktop picture visible, if they are not they reappear without any animation. I haven't found a way to kill the animation.

Tested only on 10.6



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: renaultssoftware on Aug 06, '10 06:58:43AM

Thing is that it's in the Dock. It takes up space. How about closing it instead?

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: nperry on Aug 06, '10 12:38:16PM

I'm using this on 10.6 so individual collapsed windows don't take up dock space. However the collapsed window doesn't even show up in the Finder's window list in the dock - it is well hidden in 10.6!

The Finder won't let you close the window, only collapse it. And contrariwise you can't uncollapse it, only open it! The window remains in the Finder's (private) window list all along, it is marked as collapsed & invisible after the icons are hidden.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: nperry on Aug 06, '10 02:47:52PM

Correction to the above: the desktop is shown in the Finder's Exposé window list after it is hidden. It is just not in the Finder's window list as a hidden window.

After using the above script to hide the icons click and hold the Finder's icon in the dock. Exposé will show just the Finder's windows and at the bottom you will see a (rather dark, at least in my case) desktop; select that and the icons will all pop back - quicker than using the script :-)



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: memco on Aug 06, '10 12:11:19AM

Wow, this is cool and very clever. It seems to take a long time to restore the icons from collapsed form though. Any idea why?



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: nperry on Aug 06, '10 12:41:06PM

None at all :-( Sometimes it just pops back, normally it takes a while. The window always exists so showing it shouldn't take time...



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: gmachen on Aug 05, '10 04:52:53PM

Mac OS X 10.5.8:

AppleScript Error: "Finder got an error: Can't set collapsed of window of desktop to true."

(nperry's AppleScript)

Edited on Aug 05, '10 05:04:42PM by gmachen



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: nperry on Aug 05, '10 05:51:40PM

It works on 10.6.4, so better view it as a Snow Leopard only script.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: kylecara on Aug 05, '10 07:01:33PM

Try it now. Thanks for the hint.



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: OmniDragon on Aug 07, '10 04:00:56PM

From a Terminal Window:

chflags hidden ~/Desktop/*

and to make them come back up: chflags nohidden ~/Desktop/*



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: atsilver on Aug 10, '10 04:43:42PM

Do you know the F11 key? That's a lot more simple!



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: renaultssoftware on Aug 11, '10 07:35:13AM

Actually try the script before you comment, please. The F11 key doesn't sweep the icons off the desktop.

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
A Service to hide/show the Desktop
Authored by: chabig on Aug 19, '10 01:57:44PM

It would be nice if the description of this hint described what it actually does. Just saying that is shows/hides the desktop is pretty vague. I can use Exposé to show the desktop. How is this different? Be more descriptive please. I shouldn't have to parse a bunch of Applescript to figure out what it does.



[ Reply to This | # ]