Skip to content

Instantly share code, notes, and snippets.

@vookimedlo
Last active January 9, 2018 18:34
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 vookimedlo/d775672e8220f35898bd23506a45cc18 to your computer and use it in GitHub Desktop.
Save vookimedlo/d775672e8220f35898bd23506a45cc18 to your computer and use it in GitHub Desktop.
MacOS: Tag files from command line

Taken from https://apple.stackexchange.com/questions/131258/add-and-remove-multiple-tags-at-once-from-a-file-or-a-folder

#!/bin/bash
# copy Tags from 1 file/folder to the next

TAGS_FROM="$1"
TAGS_TO="$2"

if [[ -e "$TAGS_FROM" ]] && [[ -e "$TAGS_TO" ]]; then
  xattr -wx com.apple.metadata:_kMDItemUserTags "$(xattr -px com.apple.metadata:_kMDItemUserTags "$TAGS_FROM")" "$TAGS_TO"
  xattr -wx com.apple.FinderInfo "$(xattr -px com.apple.FinderInfo "$TAGS_FROM")" "$TAGS_TO"
else
  echo "Unexpected input, usage:"
  echo "$(basename "$0") /path/to/original /path/to/copy"
  exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment