Resolved How can I add customized attributes to my files?

Discussion in 'Mac Programming' started by AppleCat, Sep 7, 2013.

  1. AppleCat, Sep 7, 2013
    Last edited: Sep 8, 2013

    AppleCat macrumors newbie

    Jun 10, 2011
    I wish to have customized attributes for some of my files, just like how they have permissions, creation date, and so on.

    It seems that HFS+ and Spotlight supports this, and I've looked at various classes like MDItem, but the documentation on Dev Center leads me around in circles, and I get the idea that a lot of cross-references are missing. For someone new to all that material it's like navigating a maze.

    It's OK if Spotlight indexing is required, but it's necessary that the attributes persist when I copy the files around, and that this can be done programmatically without having to install plugins or any kind of additional system components.

    Any pointers?

  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    See the xattr command:

    Note the links at the end of that reference, which point to man pages for C functions like getxattr, listxattr, and setxattr.

    There are limits on which xattrs are preserved by which programs. So be prepared to make tests and experiments.

    Also see this:

    And Spotlight metadata isn't the same as xattr's. Xattrs are per-file attributes. Metadata is a separate database, filled with some data extracted from xattr's, file-embedded metadata such as ID3 or Exif tags, Posix permissions, and Posix stat(2) file state.
  3. AppleCat thread starter macrumors newbie

    Jun 10, 2011
    This is exactly what I was looking for. Thanks so much for your help.

Share This Page