Skip to content

Instantly share code, notes, and snippets.

@mjackson
Last active February 18, 2024 21:15
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjackson/6d0748fe44687877d3e44e0ef9172c9b to your computer and use it in GitHub Desktop.
Save mjackson/6d0748fe44687877d3e44e0ef9172c9b to your computer and use it in GitHub Desktop.
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
@StefKors
Copy link

MacOS 14 now has a preference for this 👌
Screenshot 2023-08-16 at 15 24 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment