I'm trying to set the values of some file metadata attributes in OS X Yosemite - kMDItemDateAdded and kMDItemLastUsedDate - the values of which can be shown using mdls <filename>. I'm trying to set their values using xattr.

I've tried this:

xattr -w com.apple.metadata:kMDItemDateAdded "2001-01-01 12:34:56 +0000" some_file.txt
xattr -w com.apple.metadata:kMDItemLastUsedDate "2001-01-01 12:34:56 +0000" some_file.txt

I've tried this:

xattr -w kMDItemDateAdded "2011-01-01 12:34:56 +0000" some_file.txt
xattr -w kMDItemLastUsedDate "2011-01-01 12:34:56 +0000" some_file.txt

...but have had no success. xattr reports no errors, but the file metadata attribute values are left unchanged.

Do you know if what I'm trying to do is possible, and if it is, where I'm going wrong?

  • Did you try xattr -l some_file.txt to look at the values after changing them? And no, I don't have an explanation for this.
    – nohillside
    Mar 9, 2015 at 21:06
  • Thanks for your response, @patrix. I've tried xattr -l some_file.txt, before and after executing the four commands listed in my question above. Before executing the commands, the attributes com.apple.metadata:kMDItemDateAdded, com.apple.metadata:kMDItemLastUsedDate, kMDItemDateAdded, kMDItemLastUsedDate aren't listed. After executing the commands, they are.
    – Benjamin
    Mar 11, 2015 at 18:12
  • However - the values of kMDItemDateAdded and kMDItemLastUsedDate, shown using mdls <filename>, are unchanged. Could it be, that the four commands listed in my question above create new attributes (shown using xattr -l some_file.txt), and that mdls <filename> gets its attribute values from elsewhere?
    – Benjamin
    Mar 11, 2015 at 18:13
  • That was my first thought as well, didn't research the topic though.
    – nohillside
    Mar 11, 2015 at 18:15

1 Answer 1


I've looked into this question as well, and it appears that the "Data Added" attribute (kMDItemDateAdded) can be queried from mdls (but not xattr), but cannot be set. There is no option for it in the setattrlist function. The comments on this SO question go into a little (but not much) more detail. The "Date Added" value appears to be derived from some other seemingly inaccessible metadata value, not stored as an extended attribute.

I would guess the same applies for the "Last Used" date.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .