10.4: Open Safari's WhereFrom URLs in the Finder

Jun 21, '05 08:05:00AM

Contributed by: ever

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.]

Comments (20)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050603115314671