Skip to content

Instantly share code, notes, and snippets.

@christopher-hopper
Last active November 21, 2018 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopher-hopper/63d31a9ec99112286e9cf53e5700b24f to your computer and use it in GitHub Desktop.
Save christopher-hopper/63d31a9ec99112286e9cf53e5700b24f to your computer and use it in GitHub Desktop.
macOS Desktop Finder Files Toggle
#!/bin/bash
# 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.
#
# https://ss64.com/osx/defaults.html
# https://ss64.com/osx/killall.html
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;
fi
# Check command exists.
# https://ss64.com/osx/defaults.html
if ! command -v defaults 1>/dev/null; then
(>&2 echo "Error: macOS user defaults system not found")
exit 1;
fi
# Read state for Finder view of desktop.
CreateDesktop="$(defaults read com.apple.finder CreateDesktop)"
# Set state for Finder view of desktop.
if [[ "$CreateDesktop" != "false" ]]; then
toggle="false"
else
toggle="true"
fi
defaults write com.apple.finder CreateDesktop "$toggle"
# Restart Finder.
# https://ss64.com/osx/killall.html
Killall Finder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment