Hide Desktop Icons With an Automator App

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.
You can also watch this video at YouTube.
Watch more videos about related subjects: Automator (50 videos), Finder (318 videos).

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.

Here is the code used in the Automator shell script:

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

Comments: 15 Comments

    Emory
    6 years ago

    Gary; I tried to copy and paste your script into Automator but it didn't work. I tried doing it as a "Work Flow" then as an "Application" but neither one would accept the pasting action. What am I doing wrong here?

    6 years ago

    Emory: Are you adding the Shell action first and then putting the script in the shell? What version of MacOS? Does it give an error message? Does it at least seem to restart the Finder?

    Greg
    6 years ago

    Gary: here is what I typed
    if $(defaults read com.apple.finder CreateDesktop);
    then
    defaults write com.apple.finder CreateDesktop false
    else
    defaults write com.apple.finder CreateDesktop true
    f1
    killall Finder

    when I run I get this message: The action “Run Shell Script” encountered an error: “zsh:7: parse error near `Finder'”

    what can I do to correct --- Thanks

    6 years ago

    Greg: You appear too have typed f1 (the letter f and the number 1) instead of fi (the letter f and the letter i).

    Greg
    6 years ago

    Gary: (a bit red faced) - thanks - guess I just need an editor - at least a new set of eyes - works great

    Joshua
    6 years ago

    Hello Gray thanks for everything,
    i just want to be clear, must i first type in the command in Terminal and then the same command on Automator, or i just need to put the commands on automator only. i am a bit confused here from your video tutorial. Thanks for helping in advance.

    Gerd Gerdes
    6 years ago

    Hello Gary,
    Thank you for the skript.
    I tried to save it as an app but that didn't work.
    The system says that i don't have the right for that.
    So i searched the position of the automator app and tried to change the permissions but that did not work.
    I work with High Sierra.
    Can you please give me an hint?

    Thanks Gerd from Germany

    6 years ago

    Gerd: I don't know what your specifics are, but keep trying. Are you using a standard account or administrator? When it asked about permissions, did you grant them?

    Gerd
    6 years ago

    Thank you Gary!

    I first hat to make a copy and then i could that.

    John Thomas
    6 years ago

    Awesome! I have wanted to this forever. Thank you, Gary!!!!!

    John Thomas
    6 years ago

    Awesome! I have wanted to this forever. Thank you, Gary!!!!!

    asish
    6 years ago

    Gary, when i hit 'Run' after entering the script the message is "This app will not receive input when run inside Automator" and "To test this application with Automator, add the "Get Specified Finder items" act at the beginning of your workflow. Remove or disable the action before running the workflow outside of Automator". Am running High Sierra. Hope you can help. Thanks ahead

    6 years ago

    asish: It sounds like you have more than just the shell script in there. Take a careful look at what you have and compare it to what I am doing in the video. Maybe start again from scratch and follow along with what I am doing in the video.

    John Stires
    6 years ago

    Is it possible to toggle displaying Finder and Desktop "stuff" using a double click on the background? My goal would be to open a Finder window as well as the icons via a double click. Thanks G.

    6 years ago

    John: Clicking on the Desktop background? No, I can't think of any way to capture that as a trigger for an action, sorry.

Comments are closed for this post.