Manually set extended attributes on arbitrary files
Jan 04, '11 07:30:00AM • Contributed by: Anonymous

Jan 04, '11 07:30:00AM • Contributed by: Anonymous
Files downloaded using Safari have their source URL recorded within the file's metadata in the form of the com.apple.metadata:kMDItemWhereFroms extended attribute. In particular, this is convenient because the information is available in the Finder (using 'Get Info') or can be used as the basis of Spotlight searches.
Unfortunately, the feature is not widely supported among other browsers and not at all for files received directly from other people.
While not as convenient as having it available as a built-in function, users of other browsers can still enjoy the organizational benefits of this feature by manually writing 'where from' information for files of their choosing.
The 'where from' metadata can be viewed on the command line using /usr/bin/xattr like this:
However, the format is not immediately obvious, apart from the hint that it is bplist (binary plist) data.
It turns out, as intuitively deduced by a poster in the below bugzilla link, the same data represented as xml is an acceptable format for 'kMDItemWhereFroms', and is much easier for the user to work with.
In short, simply substitute the desired URL (or any arbitrary unicode text for that matter) between the tags and then supply the path to the file for the following command:
The effect should be immediate, and it should be possible to view your modification by opening a new 'Get Info' window for the target file.
Full credit for this hint goes to this bugzilla thread, where this was used for Firefox.
[crarko adds: I tested this, and it works as described.]
Unfortunately, the feature is not widely supported among other browsers and not at all for files received directly from other people.
While not as convenient as having it available as a built-in function, users of other browsers can still enjoy the organizational benefits of this feature by manually writing 'where from' information for files of their choosing.
The 'where from' metadata can be viewed on the command line using /usr/bin/xattr like this:
xattr -p com.apple.metadata:kMDItemWhereFroms path_to_file
It turns out, as intuitively deduced by a poster in the below bugzilla link, the same data represented as xml is an acceptable format for 'kMDItemWhereFroms', and is much easier for the user to work with.
In short, simply substitute the desired URL (or any arbitrary unicode text for that matter) between the tags and then supply the path to the file for the following command:
xattr -w 'com.apple.metadata:kMDItemWhereFroms' '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><array><string>http://www.from.where.do.I.com</string></array></plist>' path_to_file
Full credit for this hint goes to this bugzilla thread, where this was used for Firefox.
[crarko adds: I tested this, and it works as described.]
•
[11,175 views]