Skip to content

Instantly share code, notes, and snippets.

@drdrang
Created April 28, 2016 03:21
Show Gist options
  • Save drdrang/7f31cd032609e5e7657588ecfae91644 to your computer and use it in GitHub Desktop.
Save drdrang/7f31cd032609e5e7657588ecfae91644 to your computer and use it in GitHub Desktop.
Toggle the visibility of icons on the OS X Desktop. A reworking of Craig Hockenberry's original: https://gist.github.com/chockenberry/a6a06a73cce44e29808b22d458cafdcb
#!/bin/bash
# Toggle the visibility of Desktop icons.
# Desktop icons are visible if the CreateDesktop setting is missing or
# if it exists and is set to 1, true, yes, or on (case insensitive).
# Desktop icons are hidden if the CreateDesktop setting exists and
# is set to any value other than 1, true, yes, or on.
# The $icons variable is the value of CreateDesktop if it exists or is
# the empty string if it doesn't.
icons=`defaults read com.apple.finder CreateDesktop 2> /dev/null`
shopt -s nocasematch
case "$icons" in
"" | "1" | "true" | "yes" | "on" )
defaults write com.apple.finder CreateDesktop 0 && killall Finder;;
* )
defaults write com.apple.finder CreateDesktop 1 && killall Finder;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment