The openmeta command appears to take a dual attribute approach, working with both:ĭarwin gpes3e-gjp4.local 13.4.0 Darwin Kernel Version 13.4.0: Wed Mar 18 16:20: root:xnu-2422.115.14~1/RELEASE_X86_64 x86_64 Here in Stack Overflow the question arose slightly earlier () so I'll add my answer here. Possible to tag a folder via terminal? ().With multiple answers, one of which is accepted: If ] # Are there colours?įINDERINFO=$(xattr -px "$TAGFUL") TAGS=$(xattr -px :_kMDItemUserTags "$TAGFUL") If("$TAGFUL"="$f") # Is the supplier of tags is amongst the selected files? Use xattr to read all existing tags:įor f in # For every selected file in Finder, do: In the script, the selected file(s) in Finder is/are saved to the variable $tagless, and the chosen supplier of tags is $tagfull. The colour will disappear in Finder listings, but the tag (and its colour) remains associated with the file.īash script to import tags from another file You can play around with the oddity by removing the attribute from a tagged and coloured file: $ xattr -d. If you have 800 files tagged kapow, each in a different folder, and you subsequently choose the colour blue for kapow, Finder has to find and alter attributes for every single file. This is a bizarre choice, and it is one of the reasons Finder struggles under the pressure of tagging. Mavericks handles colours and tags in different attributes, by placing tags in _kMDItemUserTags and colours in FinderInfo for every file. Amongst others :kOMUserTags, org.openmetainfo:kMDItemOMUserTags and org.openmetainfo:kOMUserTags. Mavericks' tags are in :_kMDItemUserTags, while OpenMeta tags can be in a variety of attributes. Using it without modifiers, $ xattr, gives a list of set attributes. In scripts both OpenMeta and Mavericks tags can be accessed with the command xattr. I have added comments to outline the use of bash's interaction with the tags and colours using bash script.
I wrote this Automator service, which tags the selected file with the tags of another file. I add this answer, because OP asked for a shell script and tagged it bash.
NSURLLabelColorKey: returns nil, even when a color tag is set for a file.Although you can clear a color in Finder by clicking on the color, programmatically setting a color that is already set does not clear that color. If there are multiple tags set, then this will return the index of the first color that is set, as it searches numerically through the indexes 1 through 7. NSURLLabelNumberKey: can be read/set successfully, with numbers 0-7.Here is my experience on El Capitan, with the keys related to 'tags' (Colors): I have not been able to set a tag using NSURLLabelColorKey. Here is the value-color mapping (on El Capitan): However, if multiple colors are already set on the file, then it does not clear the existing colors before setting the specified color. If this is executed on a file that only has one color, then it clears the current color, and sets the specified color. Using the NSURLLabelNumberKey key, you can set the color tags, as follows: NSURL *fileURL = [NSURL *resourceError NSURL has a slew of properties that can be set or read, through the respective setResourceValue:forKey:error: and getResourceValue:forKey:error: methods. Starting with Mavericks, it is possible to get and set color tags in Cocoa, using NSURL. ProcString = subprocess.check_output(XattrCommand, stderr=subprocess.STDOUT,shell=True) Xcommand = 'xattr -wx \n".format(XattrCommand)) HexString = 18*"0" + ReverseTable.get(ColorName) + 44*"0"
Mac os tags series#
Here is a python script which wraps that command lets you set the tag color on a file or series of files: import sys The 04 buried in the middle is setting the file color.