Last active
December 29, 2015 03:49
-
-
Save briancline/7610991 to your computer and use it in GitHub Desktop.
Read/write tags from shell on OSX Maverick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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