Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Would rather ADD 'Where From' metadata TO files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Would rather ADD 'Where From' metadata TO files
Authored by: gabester on Dec 08, '10 08:29:00AM

I would find the opposite of this more useful - i.e. a way to add a "where from" attribute to a file, for example, if you copy some of a webpage into a TextEdit document and then save that; it would be convenient to attach the originating URL to that file. I currently do this simply by pasting the URL somewhere into the text of the file itself but to be able to add it as metadata would be fantastic! Anyone who puzzles this out could contribute a great Mac OS X Hint! (Or maybe it's already been done and I missed it?) Ah, yes, after some playing around:

xattr -w com.apple.metadata:kMDItemWhereFroms "SOURCEURLHERE" /path/to/file

Note there is an error in the line which reads:

xattr -d com.apple.kMDItemWhereFroms /Path/To/File 

It should read:

xattr -d com.apple.metadata:kMDItemWhereFroms /Path/To/File 
g=
Edited on Dec 08, '10 09:19:22AM by gabester


[ Reply to This | # ]
Would rather ADD 'Where From' metadata TO files
Authored by: Michael_S on Dec 08, '10 09:10:00AM
xattr --help will give: xattr -w [-r] [-v] [-x] attr_name attr_value file [file ...].

Hence, to ad the attribute, run (in a Terminal window):

xattr -w com.apple.metadata:kMDItemWhereFroms http://www.foo.com/ filename
PS: The "delete" step in the original hint has the attribute name incorrect. It should be:
xattr -d com.apple.metadata:kMDItemWhereFroms /Path/To/File
Michael

[ Reply to This | # ]
Would rather ADD 'Where From' metadata TO files
Authored by: chucky23 on Dec 08, '10 01:03:42PM

Thanks for this. It is useful knowledge for me.



[ Reply to This | # ]
Would rather ADD 'Where From' metadata TO files
Authored by: crarko on Dec 08, '10 10:35:59AM

Thanks! I've corrected the error in the hint.

Craig A.



[ Reply to This | # ]
Would rather ADD 'Where From' metadata TO files
Authored by: renaultssoftware on Dec 08, '10 02:12:04PM

My bad. I was a little tired that evening :-/

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
Re: Would rather ADD 'Where From' metadata TO files
Authored by: Uncle Asad on Dec 08, '10 02:14:35PM

I'd been looking for the same thing for a while now and also somehow missed -w in the xattr help; thanks so much for poking around and posting this!



[ Reply to This | # ]
Re: Would rather ADD 'Where From' metadata TO files
Authored by: renaultssoftware on Dec 08, '10 05:41:15PM

How did you get xattr help? When I ask man for help with xattr, nothing good happens. I had to follow a tutorial to learn about -d.

---
http://groups.google.com/group/applescripters/
http://qgf.in/
http://www.kompilesoft.info/



[ Reply to This | # ]
Re: Would rather ADD 'Where From' metadata TO files
Authored by: barko192 on Dec 08, '10 06:45:57PM

xattr -h

usage: xattr [-l] [-r] [-v] [-x] file [file ...]
xattr -p [-l] [-r] [-v] [-x] attr_name file [file ...]
xattr -w [-r] [-v] [-x] attr_name attr_value file [file ...]
xattr -d [-r] [-v] attr_name file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to the string attr_value.
The fourth form (-d) deletes the xattr attr_name.

options:
-h: print this help
-r: act recursively
-l: print long format (attr_name: attr_value and hex output has offsets and
ascii representation)
-v: also print filename (automatic with -r and with multiple files)
-x: attr_value is represented as a hex string for input and output



[ Reply to This | # ]
Re: Would rather ADD 'Where From' metadata TO files
Authored by: Uncle Asad on Dec 08, '10 10:14:23PM

Ah, I remember now what my problem was before: xattr -w does set kMDItemWhereFroms, but does so in an invalid format (this particular attribute should be some form of binary plist, not a string). Thus the Finder and Spotlight/mdls don't recognize the attribute and don't display it.



[ Reply to This | # ]
Would rather ADD 'Where From' metadata TO files
Authored by: BLAZE_MkIV on Dec 13, '10 07:30:54AM

I have a script that runs this twice with a grep to remove all the extended attributes from all the files in a directory tree.

I do this because the BSD AFP implementation used by FreeNAS can't handle them. The really annoying part is it doesn't error out till the end of the copy operation.



[ Reply to This | # ]