Skip to content

Instantly share code, notes, and snippets.

@izackp
Last active July 14, 2021 00:46
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 izackp/8a30d9ae4da2063d7b0296bdf6b7864b to your computer and use it in GitHub Desktop.
Save izackp/8a30d9ae4da2063d7b0296bdf6b7864b to your computer and use it in GitHub Desktop.
Script to disable volume meta on MacOS (OSX)
#!/bin/bash
printf "\n** Tool to disable metadata on volume **\n\n"
printf "Enable full disk access to delete files:\n"
printf "\tSystem Preferences -> Security & Privacy -> Privacy -> Full Disk Access\n"
printf "\tAdd Terminal to have full disk access then restart the terminal\n\n"
DRIVENAME="/Volumes/$1"
if test -z "$1"
then
array=()
while IFS= read -r -d $'\0'; do
array+=("$REPLY")
done < <(find /Volumes -maxdepth 1 -type d -mindepth 1 -print0)
printf "Select a volume to disable metadata:\n"
select opt in "${array[@]}"
do
DRIVENAME=$opt
break
done
fi
echo "Updating: $opt"
### Check if a directory does not exist ###
if [[ ! -d $DRIVENAME ]]
then
echo "Directory "$DRIVENAME" does NOT exists."
exit 9999 # die with error code 9999
fi
mdutil -i off "$DRIVENAME"
rm -rf "$DRIVENAME"/.{,_.}{fseventsd,Trashes,Spotlight-V*}
find "$DRIVENAME"/ -type f -name ".DS_Store" -exec rm -f {} \;
mkdir "$DRIVENAME"/.fseventsd
touch "$DRIVENAME"/.fseventsd/no_log "$DRIVENAME"/.metadata_never_index "$DRIVENAME"/.Trashes
read -p "Find and delete all files with prefix ._ (y/n)? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
find "$DRIVENAME"/ -type f -name "._*" -exec rm -f {} \;
fi
printf "\nDone\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment