Home > Automator, Mac administration, Mac OS X, macOS, Scripting > Showing and hiding all desktop icons via the command line

Showing and hiding all desktop icons via the command line

As part of preparing for a presentation, it’s often handy to be able to hide the icons on your desktop so that folks viewing the presentation aren’t distracted by what you have stored on your desktop.

To aid with this, there are defaults commands which can be run to hide or (if hidden) show the icons on your desktop.

To hide your desktop’s icons, run the command shown below:

defaults write com.apple.finder CreateDesktop -bool false

To show your desktop’s icons, run the command shown below:

defaults write com.apple.finder CreateDesktop -bool true

After running the appropriate command to either show or hide the desktop’s icons, the Finder needs to be restarted so that it can display the changes. You can do this one of two ways:

1. Log out, then log back in
2. Run the following command:

killall Finder

Since I usually remember only at the last minute that I should hide my desktop icons, I’ve also built an Automator application named Show or Hide Desktop Icons.app to assist me with showing or hiding my own desktop’s icons. For more details, see below the jump.

Using Show or Hide Desktop Icons.app

1. If needed, download the Show_and_Hide_Desktop_Icons zip file from the installer directory in my GitHub repo.

2. Once downloaded and installed, double-click on the Show or Hide Desktop Icons application in /Applications.

Screen Shot 2016 06 26 at 12 57 24 PM

3. Depending on if your icons are visible or hidden, the following actions take place:

Visible icons:

  1. The defaults command to hide the icons is applied.
  2. The Finder process is restarted.
  3. A dialog window notifies you that the desktop icons are now hidden.

Screen Shot 2016 06 26 at 12 57 32 PM

Hidden icons:

  1. The defaults command to make the icons visible is applied.
  2. The Finder process is restarted.
  3. A dialog window notifies you that the desktop icons are now visible.

Screen Shot 2016 06 26 at 12 57 47 PM

How Show or Hide Desktop Icons.app works

Show or Hide Desktop Icons.app is an Automator application that uses shell scripting behind the scenes to run the needed commands. When the application is launched, the following process takes place:

The script inside the Automator application determines if the desktop icons are set to be hidden or visible by checking for the following conditions:

Condition:

The CreateDesktop value in the user’s ~/Library/Preferences/com.apple.finder.plist file is either not explicitly set or set with a boolean value of true.

Action:

  1. The defaults command to hide the icons is applied.
  2. The Finder process is restarted.
  3. A dialog window notifies you that the desktop icons are now hidden.
  4. The script exits.

Condition:

The CreateDesktop value in the user’s ~/Library/Preferences/com.apple.finder.plist file is set with a boolean value of false.

Action:

  1. The defaults command to make the icons visible is applied.
  2. The Finder process is restarted.
  3. A dialog window notifies you that the desktop icons are now visible.
  4. The script exits.

The shell script inside looks like this:

The total workflow looks like this:

Screen Shot 2016 06 26 at 4 14 21 PM

For those interested, all Show or Hide Desktop Icons.app components and scripts are available via the GitHub repo linked below:

https://github.com/rtrouton/Show-or-Hide-Desktop-Icons

  1. June 26, 2016 at 11:27 pm

    Invaluable tip, great for giving presentations and not having to file away all the stuff on one’s desktop. I’ve had TextExpander for some time, so I have a couple of shortcuts that I type in Terminal.app in order to achieve the same result.

    ‘declutter’ expands to: defaults write com.apple.finder CreateDesktop -bool false && killall Finder
    ‘reclutter’ expands to: defaults write com.apple.finder CreateDesktop -bool true && killall Finder

    There’s also an invisible carriage return in the expansion, which triggers the change immediately.

  2. Joss Brown
    June 27, 2016 at 12:21 am

    I have it as “Toggle Desktop” in my System Menu BitBar plugin. But I never use it, because I don’t use my Desktop. 😉 I always file everything immediately where it belongs.

    • Joss Brown
      June 27, 2016 at 12:22 am

      My real world desktop is a mess, though. 😉

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: