If you have a cluttered Desktop, you may want to occasionally hide the icons. You can do this with third-party apps or Terminal commands. You can also write a very simple shell script in Automator and save it as an app. Then you can toggle the Desktop on or off with a simple click in the Dock.

Check out Hide Desktop Icons With an Automator App at YouTube for closed captioning and more options.

Video Transcript: Hi, this is Gary with MacMost.com. Let me show you how you can quickly and easily hide the icons on your desktop with a simple app you can create in Automator. MacMost is brought to you thanks to a terrific group of supporters. Join us and get exclusive content at MacMost.com/patreon. So if you have a cluttered desktop with a bunch of stuff on there you may want to occasionally want to hide it. Maybe to give a presentation or just to get stuff out of the way so you can concentrate on what you're doing. Now you can do that using a terminal command and I'm going to show you how. But then we're going to use that terminal command to build a simple app in Automator that will allow you to toggle the desktop on and off. So let's start off by going to the Terminal. There's a Terminal command that you can use to hide the desktop icons. That is use defaults write, which is what you use to change a system preference. One that isn't in the System Preferences app. We have to identify the group of system preferences. In this case com.apple.finder in other words system preferences that have to do with the Finder. The specific preference is CreateDesktop. This is what will create the desktop including the icons when the Finder runs. We will set it to false. When we run it nothing is going to happen at first because all we've done is change the preference. If we restart the Finder, and you can do that with killall, one word, Finder. Then it will relaunch the Finder and this time we won't have icons on the desktop. There's nothing there. Not only that but if you click on the background nothing happens. It doesn't switch to the Finder because the desktop is no long part of the Finder. So there are two advantages to actually having this turned off. To turn it back on we use the same command again. I'm going to use up arrow here in the Terminal to go back there but replace False with True. Then run killall Finder again and we'll get our icons back. So that's how you do it in the Terminal. But you don't want to have to type this every time you want to hide these. You want it to be quick and easy. So we're going to write an Automator script. Something that uses these same commands. So let's run Automator and we'll select Application as the type here. Then we're going to search here for Shell because we want to use Run Shell Script. In other words we can do exactly what we did before. I'm going to change the shell type to Z shell, since that's going to be the default in Catalina anyway. But the same thing will work with the Bash shell too. So we can add the same thing in here. When I run this it will turn off the desktop. If I change false to true we can get the desktop back by running it again. Now what would be nice is if we could toggle them and we can because we can use an if statement inside of the shell. So we can do if and I'm going to do dollar sign and then parentheses and then semicolon. if $ (); in here is where we want to put the condition. We can do the same thing we've got here but instead of writing to the preferences we can read from them. So I'm going to copy and paste this here and change write to read. So it's going to read the value of create desktop. Then we can use then and if this value is true then what we're going to do is set it to false else and we'll set it to true. So in other words do the opposite and you'll end if then with fi, the opposite of if. Then we killall Finder regardless of whether we're saying false or true. So now it's a toggle. Let's test it out. We run it and we can see it turns off the desktop. If we run it again it'll toggle it back on and turn the desktop back on. Now we can save this and it becomes an Application. So we can save it anywhere we want. I can just put it in a folder there in my Home folder. We'll call it Toggle Desktop and save it there. Now I can quit Automator. I can bring up the Finder here and go to that application. I can stick it in my Applications folder too. That's probably a better place for it. Or maybe even inside of Utilities in Applications. If I run it here it will do the same thing. You can see it's restarting the Finder. I'm going to get the Finder back. Now I want you to notice that you can still get to your desktop files in the Finder. The folder is still there. The file is still there. It's just not visible in a second location which is on the desktop. So if I toggle it again it will go back on and I'll get the icons back. Now what I could do is I could take that app and drag it into the Dock for even easier access. So I'll stick it in the Dock there and I can get rid of it there. Now I can just double click it in the Dock to run it and it will turn them off. Double click it again and it will turn the desktop back on. You can also make it a service or quick action in Automator and then it's available in the Services menu. You can make it a dictation command. There's all sorts of things you can do to make the Automator action readily accessible.

if $(defaults read com.apple.finder CreateDesktop); then defaults write com.apple.finder CreateDesktop false else defaults write com.apple.finder CreateDesktop true fi killall Finder

Here is the code used in the Automator shell script: