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

Delete 'Where From' metadata from files Apps
Recently, I was asked to find a way to delete the 'Where From' link in the Get Info box of the Finder, because the info key was too incriminating. I didn't want to download any software, so I set about looking in the file's metadata. After running mdls and xattr on the file, I finally hit upon a way to delete the key.

If you run xattr on your downloaded file, like this:

xattr /Path/To/File

You'll get a key named com.apple.metadata:kMDItemWhereFroms. To delete this key in the Terminal, run:

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

I knew I would have to do this often, so instead of running a shell script every time I wanted to strip the Where From, I wrote an AppleScript:
on deleteWhereFrom(fileToClean)
 try
  set posixPath to quoted form of POSIX path of fileToClean
  do shell script "xattr -d com.apple.metadata:kMDItemWhereFroms " & posixPath
 end try
end deleteWhereFrom
on open imgs
 repeat with i in imgs
  deleteWhereFrom(i)
 end repeat
end open
on run
 set imgs to choose file with multiple selections allowed
 repeat with i in imgs
  deleteWhereFrom(i)
 end repeat
end run
I then saved it on the desktop as an application. Now, I can drag and drop as a batch operation to delete the metadata key.

[crarko adds: I tested this, and it works as described.]
    •    
  • Currently 4.00 / 5
  You rated: 5 / 5 (7 votes cast)
 
[27,322 views]  

Delete 'Where From' metadata from files | 16 comments | Create New Account
Click here to return to the 'Delete 'Where From' metadata from 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 | # ]
Delete 'Where From' metadata from files
Authored by: mchagers on Dec 08, '10 12:30:38PM

It may be of interest that Safari doesn't add this link on files downloaded in privacy mode.



[ Reply to This | # ]
Delete 'Where From' metadata from files
Authored by: ericcartman on Dec 09, '10 02:26:44PM

wow. thats an amazing observation. thanks. the applescript stuff sounds really exciting but is way over my head.



[ Reply to This | # ]
Delete 'Where From' metadata from files
Authored by: afingal on Dec 09, '10 10:05:53AM

So, apparently, the "Where From" metadata is something which gets added by Safari. Files downloaded with Firefox don't have it. This is something you can search by in Spotlight if you go to the "other" category. You can search for files downloaded from a particular site. This could be very handy in some cases but I also see the security/privacy risk. That's why this hint is so valuable.



[ Reply to This | # ]
Delete 'Where From' metadata from files
Authored by: JimMueller on Dec 15, '10 07:00:04PM

In pre-X days, Internet Explorer (of all things!) placed the source URL for downloads in the files comment field. Then when System 9 came out, it no longer did so.
We always found this to be incredibly useful to track back on what site we found various images.
What would be really useful now would be to be able to select and copy text (like the source url) in GetInfo windows...



[ Reply to This | # ]
Delete 'Where From' metadata from files
Authored by: xantron on Sep 07, '11 05:18:10PM

For what it's worth, Mail also adds a "Where From" to a file's info.

Many thanks for the AppleScript; I just used it to zap email address, subject line, etc. from images my client wants me to post to her site.



[ Reply to This | # ]
Delete 'Where From' metadata from files
Authored by: dedalus27 on Mar 25, '13 03:06:56AM
You could use xttra -c
With -c option is possible to clear all attributes including their associated values. In case of a downloaded file:
com.apple.metadata:kMDItemDownloadedDate
com.apple.metadata:kMDItemWhereFroms


[ Reply to This | # ]