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

10.4: Open Safari's WhereFrom URLs in the Finder Web Browsers
Tiger only hintAs noted in an earlier hint, Tiger has added the "Where From:" field to downloaded files. Unfortunately there is no easy way to open these unselectable URLs in Safari.

This script solves that problem by popping up a window showing all the available URLs for the currently selected file. Double-clicking a URL will load it in Safari.
try
  tell application "Finder"
    set theFile to selection as alias
    set theFile to POSIX path of theFile
  end tell
  set AppleScript's text item delimiters to """
  set theInfo to (do shell script "mdls -name kMDItemWhereFroms " & quoted form of theFile)
  set url1 to (text item 2 of theInfo) as text
  set url2 to (text item 4 of theInfo) as text
  set theURLs to {url1, url2}
  set theURL to (choose from list theURLs) as string
  if theURL is not "false" then
    tell application "Safari"
      make new document at end of documents
      set URL of document 1 to theURL
    end tell
  end if
  set AppleScript's text item delimiters to ""
on error
  display dialog "Sorry, no "Where From" URLs were found."
end try
[robg adds: I tried this, and it worked great. I saved the script as an Application, with Run Only and no startup screen. I then put the script in the toolbar, selected a download, and clicked the toolbar icon. Presto, a floating URL box shows up listing the two URLs embedded in the chosen file's WhereFrom field.]
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[9,241 views]  

10.4: Open Safari's WhereFrom URLs in the Finder | 20 comments | Create New Account
Click here to return to the '10.4: Open Safari's WhereFrom URLs in the Finder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: mike666 on Jun 21, '05 12:10:14PM

I got a couple of errors: the extra quote at the end of line 6 needed to be removed and the double quotes around "Where From" in the error dialog either need to be changed to single quotes or escaped somehow.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: mike666 on Jun 21, '05 12:21:28PM
Correction: the middle quote of the three at the end of line six should be escaped so the line should read
	set AppleScript's text item delimiters to "\""
Simply removing one of the quotes kills the script's parsing ability.

[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: jonn8n on Jun 21, '05 12:15:19PM
Here is a revised version of the script that corrects the non-escpaed quotes issue, allows you to use your default browser to open the URL (i.e., it's not dependent on Safari), and is a little cleaner (IMO):
try
	tell application "Finder" to set the_file to POSIX path of ((item 1 of (get selection)) as alias)
	set the_info to (do shell script "mdls -name kMDItemWhereFroms " & quoted form of the_file)
	tell (a reference to my text item delimiters)
		set {old_tid, contents} to {contents, "\""}
		set {the_URLs, contents} to {{the_info's text item 2, the_info's text item 4}, old_tid}
	end tell
	set this_URL to (choose from list the_URLs) as Unicode text
	if this_URL = "false" then return
	open location this_URL
on error
	display dialog "Sorry, no \"Where From\" URLs were found." buttons {"OK"} default button 1 with icon 2 giving up after 5
end try
Jon

[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: jonn8n on Jun 21, '05 12:29:10PM
Here's a version that can be saved as an application and will allow you to drag and drop files onto it or continue to use it as before (get the file to target from the current Finder selection):
on run
	try
		tell application "Finder" to set the_selection to item 1 of (get selection)
		open {the_selection}
	on error
		display dialog "Sorry, nothing is selected in the Finder. Please try again." ¨
			buttons {"OK"} default button 1 with icon 2 giving up after 5
	end try
end run

on open the_selection
	try
		set the_file to POSIX path of ((item 1 of the_selection) as alias)
		set the_info to (do shell script "mdls -name kMDItemWhereFroms " & quoted form of the_file)
		tell (a reference to my text item delimiters)
			set {old_tid, contents} to {contents, "\""}
			set {the_URLs, contents} to {{the_info's text item 2, the_info's text item 4}, old_tid}
		end tell
		set this_URL to (choose from list the_URLs ¨
			with prompt "The selected file is linked to the following URLs. Select a URL to open:") as Unicode text
		if this_URL = "false" then return
		open location this_URL
	on error
		display dialog "Sorry, no \"Where From\" URLs were found." ¨
			buttons {"OK"} default button 1 with icon 2 giving up after 5
	end try
end open
Jon

PS Rob, don't save this as Run Only, that only means you can never edit it again. Disabling the Startup Screen option is all you need to do to get it to run unobtrusively.

[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: Twist on Jun 21, '05 02:13:31PM

Great job.

I suggest sticking this script into an Automator Workflow so that it can be used with the Automator Contextual Menu item.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: mark hunte on Jun 21, '05 02:24:49PM

if you want to save it as an run only app do it as a run only - application bundle -

you can always open the package and edit the script from there.

whereFrom.app/Contents/Resources/Scripts/main.scpt



---
mh



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: sjk on Jun 22, '05 07:59:44PM

Thanks, Jon! How hard would it be to modify for handing multiple selections of files?



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: ever on Jun 24, '05 10:12:08PM

Wow, what an elegant rewrite! Thank you.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: robJ on Jun 21, '05 04:25:32PM

I'm running 10.4.1 and I see no "Where From:" info for any of my downloaded files. Any ideas why not?



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: boredzo on Jun 22, '05 04:39:41AM

they're in the 'More Info' section.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: bdog on Jun 22, '05 07:50:04AM

I also don't have that info in downloaded files, not in More Info. And I am making sure that I am getting info on the original, uncompressed file, as I think this info is lost after uncompressing something you downloaded.

I use Camino nightlies. Gonna go post a thread on this @ mozillazine... After I confirm on another computer.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: robJ on Jun 22, '05 09:17:27AM

Nope, the info isn't there. I've even downloaded files for the sake of checking this hint and there is no "More Info" available in the Get Info window or via the scripts offered in the hint. :/



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: sjk on Jun 22, '05 07:55:20PM

Which browser(s) did you try? It may be a feature of WebKit/WebCore so it won't work with Firefox, et.al.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: englabenny on Jun 22, '05 08:10:18PM

There's no magic involved; the application doing the download has to set this piece of metadata. I think that currently, only Safari does this.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: robJ on Jul 02, '05 12:24:09PM

I used Safari to download the files and still no extra info.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: robJ on Jul 22, '05 07:13:20AM

I've discovered why I was seeing no "More Info" on my downloaded files. It seems that Spotlight is responsible for providing this info and I had excluded my Downloads folder from Spotlight indexing.



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: Zonker1967 on Nov 01, '06 10:17:52PM

Old topic, I know....

If you download a file with Safari, it will set the Where From: field. But if you copy that file somewhere else, even on the same volume, it's gone. I just discovered this. So, this means, either make sure you don't move your files after downloading them or we need to find out a way to keep that data intact.

Does anyone know of a copy utility which will keep all metadata intact?



[ Reply to This | # ]
10.4: Open Safari's WhereFrom URLs in the Finder
Authored by: dave1212 on Jul 28, '05 02:09:29PM

It's not a persistent thing though, so if you copy that file somewhere else (say, a different partition) and the delete the original, there will be no record of which URL it came from. (the WhereFrom URL disappears)This sucks for me, as I keep most of my stuff on other partitions, but download to a folder on my desktop.

Any chance an AppleScript whiz can set us up with one that copies the URL to the comments field or something? It's really annoying that the info doesn't stay with the file.

This is really bugging me.

---
______
http://www.macskill.com/



[ Reply to This | # ]
Set Comment to "Where From" URI.scpt
Authored by: Rainy Day on May 14, '08 07:02:22PM
Save this script into Library/Scripts/Applications/Finder/ and you can easily invoke it from the Finder via the Script Menulet. Works on the frontmost window. Works on either a Get Info window, or a Finder window with one or more selected files:

tell application "Finder"
	if the class of window 1 is information window then -- If a Get Info window
		fetchWherefromData(item of window 1 as alias, true) of me
	else if the class of window 1 is Finder window then -- If a regular Finder window
		repeat with thisItem in the selection as list -- may have multiple files selected
			fetchWherefromData(thisItem as alias, true) of me
		end repeat
	end if
end tell
beep

(*  Grab the WhereFrom metadata; If "setComment" is true, put it into the file's comment box  *)
on fetchWherefromData(theFile, setComment)
	set theURI to do shell script "mdls -name kMDItemWhereFroms " & quoted form of POSIX path of theFile & " | perl -ne 'print if s/.*"(.*)".*$/\1/'" --  shell script to fetch metadata; using Perl to extract URI from mdls's messy output
	if setComment = true then -- Put it into the file's comment box?
		if theURI ‚Ȇ "" then -- did we get a URI?
			tell application "Finder"
				set theComment to comment of theFile
				if theComment = "" then -- if no comment exists, put in the URI
					set comment of theFile to theURI
				else if theComment ‚Ȇ theURI then -- if the comment is the URI, do nothing, else append the URI to the end of the comment
					set comment of theFile to theComment & return & theURI
				end if
			end tell
		end if
	end if
	return theURI
end fetchWherefromData


[ Reply to This | # ]
Another Re-write
Authored by: Rainy Day on May 15, '08 12:35:52AM
Works on the frontmost Finder window. Works on either a Get Info window, or a Finder window with one or more selected files. If Where From metadata isn't available, it will look in the Comment box for a URI.

Save this script into Library/Scripts/Applications/Finder/ and you can easily invoke it from the Finder via the Script Menulet:

tell application "Finder"
	if the class of window 1 is information window then -- If a Get Info window
		openURI(item of window 1 as alias, true) of me
	else if the class of window 1 is Finder window then -- If a regular Finder window
		repeat with thisItem in the selection as list -- may have multiple files selected
			openURI(thisItem as alias, true) of me
		end repeat
	end if
end tell
beep

(*  Grab the WhereFrom metadata; if that fails and "tryComment" is true, try to fetch URI from file's comment box  *)
on openURI(theFile, tryComment)
	set theURI to do shell script "mdls -name kMDItemWhereFroms " & quoted form of POSIX path of theFile & " | perl -ne 'print if s/.*"(.*)".*$/\1/'" --  shell script to fetch metadata; using Perl to extract URI from mdls's messy output
	if theURI ‚Ȇ "" then -- did we get a URI?
		open location theURI
	else if tryComment = true then -- Look in the file's comment box?
		tell application "Finder" to set theComment to comment of theFile
		repeat with thisLine in every paragraph of theComment as list
			if thisLine starts with "http://" or thisLine starts with "https://" then -- if a comment exists and it looks like it might be a URI, try it
				open location thisLine
			end if
		end repeat
	end if
end openURI


[ Reply to This | # ]