DIY: Hide The Mac Desktop

Mojave with hidden desktop
macOS Mojave introduced stacks to organize and clean up the desktop.  I like and use that feature, but sometimes, I want to go a little more minimalist and hide my desktop entirely.

Those who have bitten the Apple already know the commands to hide and show the desktop.





Hide:
defaults write com.apple.finder CreateDesktop -bool false && killall Finder

Show:
defaults write com.apple.finder CreateDesktop -bool true && killall Finder

For the uninitiated, I will explain the commands and help you put them in a couple of scripts so you can hide and show the desktop at will.

First, you will need to launch the terminal app.  It lives in the Utilities folder, but you can also use Apple's Spotlight Search and type in "terminal"


Finding terminal app
Once you launch the terminal, you can type in the above commands and watch your desktop hide and reveal itself respectively.

The defaults command gives you access to the Mac OS user default settings.  You can read the value of CreateDesktop, or in this case, write a new value.  Setting it to false hides the desktop while setting it to true shows the desktop.

Not all processes will be aware of the change though, and that's where && killall Finder comes in.  killall is a command that runs after the new default is set, killing the Finder process and restarting it with the new setting.

Clearly, typing these commands every time you want a change gets tedious very fast.  The idea, then, is to create two scripts -- hidedt and showdt -- that will embody what you want to do.  You will need an editor (vim is built-in) to create these scripts, and you should put the scripts in a readily accessible location.

When you first open a terminal, it deposits you into your home directory: /Users/<your username>.  Create a Scripts directory for your scripts.  Because Apple's starts directory names with a capital letter, I am following that convention. 

$ mkdir Scripts

Go into the Scripts directory with the "change directory" command:

$ cd Scripts

If you get lost, you can always check where you are with the "print working directory" command:

$ pwd 
/Users/<your username>/Scripts

At this point, you will need your favorite editor to create hidedt and showdt.  If you don't have one, you can always use vim.  Explaining vim, however, is beyond the scope of this article, but here's a tutorial: https://vim.fandom.com/wiki/Tutorial.

Admittedly, there is a work-around that avoids using an editor of any kind, and it's the echo command:

$ echo "defaults write com.apple.finder CreateDesktop -bool false && killall Finder" > ./hidedt
$ chmod +x hidedt

This creates the hidedt script with the defaults command in it.  The chmod command -- change mode -- makes the script executable, meaning  if you type ./hidedt now, your desktop will be hidden.

Use the echo command to make the show desktop counterpart:

$ echo "defaults write com.apple.finder CreateDesktop -bool true && killall Finder" > ./showdt
$ chmod +x showdt

Now type ./showdt to show your desktop.

There's still a loose-end though.  It's a minor nuisance to always go to the Scripts directory to run your commands.  To fix your environment so you can run the commands from anywhere, you will need to edit a special file named .bash_profile.

In this case, there's no way to avoid using an editor.

$ cd <enter>
$ pwd
/Users/<your username>

$ vi .bash_profile

vi .bash_profile


You will need to add:

PATH=$PATH:~/Scripts

which directs your environment (a.k.a. shell) to look for commands in the Scripts directory.

There's one last wrinkle to address.  If the desktop is hidden, there's no quick way to access those files unless your create a shortcut in the Dock.  Open Finder and right click on Desktop.  There will be an option to "Add to Dock."

Add Desktop to Dock


And there you have it, hide and seek with your desktop.  If you're feeling really minimalist, you can hide the Dock and the Menu Bar as well. No need for commands as you can find those options in the System Preferences. 



Comments

Popular posts from this blog

Bookshelf: UNIX A History and a Memoir

Bookshelf Classic: The C Programming Language

Connections