Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
macOS Desktop Finder Files Toggle
# vim: ai ts=2 sw=2 et sts=2 ft=sh
# macOS Desktop Finder Files Toggle
# Toggle the use of Finder to display the contents of the Desktop folder as
# icons on the macOS desktop. Hides or Shows all Finder files icons on the
# Desktop.
set -o errexit
set -o nounset
set -o pipefail
# Check OS type.
if [[ "${OSTYPE//[0-9.]/}" != "darwin" ]]; then
(>&2 echo "Error: This script is for macOS not '${OSTYPE}'.")
exit 1;
# Check command exists.
if ! command -v defaults 1>/dev/null; then
(>&2 echo "Error: macOS user defaults system not found")
exit 1;
# Read state for Finder view of desktop.
CreateDesktop="$(defaults read CreateDesktop)"
# Set state for Finder view of desktop.
if [[ "$CreateDesktop" != "false" ]]; then
defaults write CreateDesktop "$toggle"
# Restart Finder.
Killall Finder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.