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


Click here to return to the 'Another Re-write' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
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 | # ]