Skip to content

Instantly share code, notes, and snippets.

@JayBrown
Last active June 4, 2023 22:36
Show Gist options
  • Save JayBrown/ab176d111077c5c168316f0c8168033f to your computer and use it in GitHub Desktop.
Save JayBrown/ab176d111077c5c168316f0c8168033f to your computer and use it in GitHub Desktop.
quick script to run a .DS_Store deletion process on volumes
#!/bin/zsh
# shellcheck shell=bash
# rm-dsstore v0.2
# macOS Catalina and later only!
if [[ $(id -u) != 0 ]] ; then
echo "Please run as root user!" >&2
exit
fi
if ! [[ $* ]] ; then
echo "Deleting all .DS_Store files on the boot volume..."
find "/System/Volumes/Data" -type f -name \( -name .DS_Store -o -name ._.DS_Store \) -print -delete 2>/dev/null
else
for volume in "${@}"
do
if [[ $volume == "/" ]] ; then
echo "Deleting all .DS_Store files on the boot volume..."
volume="/System/Volumes/Data"
else
volname=$(basename "$volume")
if ! [[ -d "$volume" ]] ; then
echo "Target does not exist: $volname" >&2
continue
else
if ! [[ -w "$volume" ]] ; then
echo "Target is not writable: $volname" >&2
continue
else
echo "Deleting all .DS_Store files in: $volname"
fi
fi
fi
find "$volume" -type f \( -name .DS_Store -o -name ._.DS_Store \) -print -delete 2>/dev/null
done
fi
[[ $(pgrep -x Finder) ]] && { echo "Restarting Finder..." ; killall Finder ; }
echo "Done"
exit
@JayBrown
Copy link
Author

v0.2: also removes ._.DS_Store AppleDouble files… now only for Catalina & later

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