Erik Ableson 2 minute read
May 15, 2008

Getting extended attribute file information

Now here's something potentially useful. I'm often writing up documentation for clients and use PDF files that I've downloaded from various sites for supporting information. I can't simply copy the whole PDF into a Word document and dragging a multipage PDF document into Pages just imports the first page. So the usual solution is to note the URL where you can go get the document and put that into the text. Of course if you're like me, you have a ton of files downloaded and I certainly don't bookmark each and every one of them.

So what to do? Well, under 10.5 Apple has intelligently decided to give you some breadcrumbs in the extended attributes, including the URL from whence you downloaded the file. Except that it's tantalizingly out of reach. You can see it in the Get Info window, but you can't copy and paste it into your document. Nor can you click on the link to bring it up in Safari (note to self: file a bug report on that one). I'm not sufficiently masochistic to want to retype out some of these URLs that are usually buried 4 levels down on a vendor site so I went poking around on the command line.

Sure enough there's an easy way to get this information out fairly easily. On the command line the mdls command will happily dump out all of the various metadata information on the file, including the very useful "kMDItemWhereFroms" attribute. From there it's a simple copy and paste operation. Or you can be more specific and ask for this value only by specifying it by name:

mdls -name kMDItemWhereFroms myFile