Set file metadata attribute values

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?


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.