Last active
November 21, 2018 05:23
-
-
Save christopher-hopper/63d31a9ec99112286e9cf53e5700b24f to your computer and use it in GitHub Desktop.
macOS Desktop Finder Files Toggle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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