If you’re someone like me who works in IT and takes screenshots multiple times a day on a Mac, your desktop might look something like this,
I’ll show you how you can quickly hide or show icons on your desktop on macOS from the Terminal.app.
In macOS by default, when you take a screenshot, the new screenshot will end up on your desktop. This is convenient because usually screenshots are files you’ll need to easily and quickly reference to communicate details or issues to a teammate.
Unless you’re disciplined with cleaning your desktop regularly, it can quickly get out of control as you’ve seen in the screenshot above.
But let’s say you’ve got an important presentation coming up or you might want to do a screen recording. Seeing your cluttered desktop could be embarrassing and not to mention a distraction for your audience.
You don’t have the time to sift through all the screenshots and files to tidy up right now. And jamming everything into a folder just won’t cut it.
By running a couple of commands from Terminal.app you could solve this easily.
Assumptions
Before I get into the command that actually hides and shows icons on your desktop, I assume in this article that you know where Terminal.app is on macOS and that you feel fairly comfortable running commands from the command-line.
Hiding your desktop icons on macOS from Terminal
You’ll first want to open up a session in Terminal. Then you’ll want to run this command,
defaults write com.apple.finder CreateDesktop false
Sad trombone…
The command doesn’t do anything immediately to your desktop. To see the results of the command, you’ll want to run,
killall Finder
What this command does is tell Finder to restart.
Once you run this command, your desktop should be spotless, leaving you with a pristine desktop with just your background image.
Uhmmm but where the heck did all my files go?
So not to worry. At first glance, it might look like all your files went missing. I hope this doesn’t cause you any anxiety or spikes in blood pressure.
Rest assured that your files are still on your machine, just not visible currently from your desktop. If you open up a new Finder
instance and navigate to the Desktop
folder, you should see all the files that was previously viewable on your desktop.
Can I get my desktop icons to show again?
Sure can, the process is reversible! To do so you’ll want to go back into Terminal.app and then run this command,
defaults write come.apple.finder CreateDesktop true
Then, don’t forget to restart Finder
by running,
killall Finder
And voila! Your cluttered desktop state is restored.
Going the extra mile
If showing and hiding your desktop icons is something you’ll be doing often, here’s something you could do to make the process easier.
By default since macOS Catalina, Terminal.app uses zsh as its default shell. What this means is that we can take the commands to hide and show desktop icons and put them into shell functions defined in our .zshrc
file where other run commands are defined.
If you’re not familiar with the .zshrc
file you can find it on your user directory at ~/.zshrc
. If it doesn’t exist you can create one by typing in,
touch ~/.zshrc
Open up your .zshrc
file and we’ll first define a function to hide the icons on your desktop.
hide() {
defaults write com.apple.finder CreateDesktop false
killall Finder
}
The function I created is called hide()
what this mean is that the next time I start a new Terminal session, I’ll be able to type in hide
and it’ll run both the commands to both hide and restart finder.
Now let’s define a function to unhide the desktop icons once again.
unhide() {
defaults write com.apple.finder CreateDesktop true
killall Finder
}
After you’re done defining these new functions in your .zshrc
file, save and exit the file.
When you run these new commands, you’ll notice that Terminal complains about the functions being undefined. This is because your session hasn’t loaded these new functions and so are not aware of them.
You can fix this by opening up a new Terminal window or you can run this command which reloads your .zshrc
file into the current session,
source ~/.zshrc
Now running either commands hide
or unhide
should do the intended action on your desktop.
Here’s to a clean and happy desktop. I hope you have a good presentation, screen cast or whatever you’re doing that may need your desktop to be clean!