objective-cfilemetadatacustomizationspotlight

Applying Custom Metadata to Files


I've been trying to figure out a way to give files custom metadata. An example of this would be giving files tags, but that's not the only sort of custom metadata I want to apply. I've looked at a couple posts like these ones - Adding custom metadata to jpeg files, Can I add custom metadata to files?, Set Custom Metadata to Files of any Type - but they all deal with languages other then Objective-C, which is the language that I'm trying to use for the custom metadata. I've looked at Apple's documentation like the File Metadata Attributes Reference and the NSMetadataItem Class Reference, but I haven't found anything related to custom metadata.

My question basically is, is it possible to apply custom metadata to files and if so, how would I go about doing it?


Solution

  • Custom metadata can be created by a custom MDImporter. This is a plug in for Spotlight which allows the operating system to view/scan/search custom documents. So your metadata would end up in the spotlight search index. However your spotlight importer plug in would have to extract the metadata from the file itself somehow.

    You can also store metadata in the file's resource fork which is a MacOS 9 and older way of dealing with associated data. This would only work under HFS+ formatted volumes and would create two file under other filesystems such as NFS. Also simple unix tools such as cat FILE1 > FILE2 would only copy the data part and potentially break the purpose. I would not recommend this.

    Or you could use so called extended attributes to a file which is for example the way the finder remembers from where you downloaded a specific file so it can ask you if you really wanted to execute downloaded from at first launch. (see getxattr(2), listxattr(2), removexattr(2) and setxattr(2) or

    From the command line: "xattr" or "ls -l@" From C: getxattr(), listxattr(), removexattr() and setxattr()