Skip to content

Instantly share code, notes, and snippets.

@briancline
Last active December 29, 2015 03:49
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 briancline/7610991 to your computer and use it in GitHub Desktop.
Save briancline/7610991 to your computer and use it in GitHub Desktop.
Read/write tags from shell on OSX Maverick
# Read existing tags, output as JSON string
xattr -p com.apple.metadata:_kMDItemUserTags ${file} | xxd -r -p | plutil -convert json -o - -
# Write tags to file
PLIST_START='<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><array>'
PLIST_END='</array></plist>'
XTAG="Red\n6"
XTAG_PLIST="${PLIST_START}<string>${XTAG}</string>${PLIST_END}"
XTAG_BINARY_PLIST=$(echo -e $XTAG_PLIST | plutil -convert binary1 -o - - | xxd -c16 -g2 -p)
xattr -wx com.apple.metadata:_kMDItemUserTags "$XTAG_BINARY_PLIST"
# https://github.com/marijnvdwerf/FolderListing/blob/master/File.php
# 1 => 'grey',
# 2 => 'green',
# 3 => 'purple',
# 4 => 'blue',
# 5 => 'yellow',
# 6 => 'red',
# 7 => 'orange'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment