Since Mavericks, OS X has had the ability to tag & colour files in Finder.
Is there any way to add tags to files through Cocoa APIs or via a shell command?
Since Mavericks, OS X has had the ability to tag & colour files in Finder.
Is there any way to add tags to files through Cocoa APIs or via a shell command?
The OpenMeta framework is a third-party standard for adding metadata to OS X files using extended attributes. It is used by a number of third-party applications.
Or you can use the XATTR command to manipulate the extended attributes via command line.
Check out tag, "a command line tool to manipulate tags on Mac OS X 10.9 Mavericks files, and to query for files with those tags". The GitHub repository has installation instructions (there are Homebrew and MacPorts packages).
Sorry for adding another answer, but the one related to setting Label colors was pretty long already. Here is an excerpt from a python script that I use to set the User Tags. It seems to work to make things searchable, but not sure if the tags will show up correctly. Usage is basically:
Code below.
You could give this a shot:
You'll want to replace $currentFile with the file you'd like to add tags to, and change
to a list of whatever tags you want to add.
This does not cover tags, but for changing label colors, one way to do it is through a command like this:
The
04
buried in the middle is setting the file color.Here is a python script which wraps that command lets you set the tag color on a file or series of files:
Usage is:
where [color] is a name or abbreviation as defined below:
In Ask Different
With multiple answers, one of which is accepted:
Here in Stack Overflow the question arose slightly earlier (2013-11-01) so I'll add my answer here.
openmeta
Open source at https://code.google.com/p/openmeta/source/browse/trunk/trunk/openmeta
The
openmeta
command appears to take a dual attribute approach, working with both:com.apple.metadata:kMDItemOMUserTags
com.apple.metadata:_kMDItemUserTags
Example usage
Limitations of other utilities
Apple Finder, for example.
After using Finder to remove the kerfuffle tag, kerfuffle remains as an OpenMeta tag:
Understanding those limitations
With attention to domains and naming conventions: Developer thoughts on adopting OpenMeta – Ironic Software (2009-03, and now in the Internet Archive Wayback Machine) reminds us that
com.apple.metadata
was for use by Apple when OpenMeta (a project not in theapple.com
domain) began the Apple-orientedcom.apple.metadata:kMDItemOMUserTags
approach.So I should not expect Apple software to gain or maintain compatibility with both approaches to tagging.
Edge cases
In some cases it may be desirable to remove Apple-oriented
com.apple.metadata:_kMDItemUserTags
tags without removing OpenMeta-orientedcom.apple.metadata:kMDItemOMUserTags
tags.However, doing so – programmatically – is probably beyond the scope of the question asked by @nacross.