Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quickly show/hide desktop icons on macos
#!/bin/bash
# To install: just copy this script to your machine and name it whatever you want.
# Let's say you named it toggle-desktop-icons.sh, then all you need to do is make
# the script executable, like this:
#
# chmod +x toggle-desktop-icons.sh
#
# Now you can execute the script directly in the terminal any time you want to
# show/hide the desktop icons, like this:
#
# ./toggle-desktop-icons.sh
prevValue=$(defaults read com.apple.finder CreateDesktop 2>&1)
nextValue=$([[ "$prevValue" == "true" || "$prevValue" == *"does not exist"* ]] && echo "false" || echo "true")
if [[ "$nextValue" == "true" ]]; then
echo "Showing desktop icons..."
else
echo "Hiding desktop icons..."
fi
defaults write com.apple.finder CreateDesktop $nextValue
killall Finder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment