Skip to content

Instantly share code, notes, and snippets.

@csparker247
Created July 26, 2023 15:06
Show Gist options
  • Save csparker247/b74ccb9bc931badbe1009b3b8c85d92b to your computer and use it in GitHub Desktop.
Save csparker247/b74ccb9bc931badbe1009b3b8c85d92b to your computer and use it in GitHub Desktop.
Get list of a file/directory's macOS color tags
# macOS Color Tags
# A shell utility for printing the list of macOS color tags
# assigned to a file or directory.
# Written by: C. Seth Parker
# Usage:
# % source macos_color_tags.sh
# % macos_color_tags foo.txt
# % macos_color_tags bar/
macos_color_tags() {
usage="Usage: macos_color_tags [file|dir]"
if [ "$#" -eq 0 ]; then
echo ${usage}
return
elif [ "$#" -gt 1 ]; then
echo "Error: Provided more than one argument"
echo ${usage}
return
fi
xattr -p com.apple.metadata:_kMDItemUserTags "$1" \
| iconv -c \
| sed -n -E 's/.*(Red|Orange|Yellow|Green|Blue|Purple|Gray).*/\1/p'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment