Automagically drag url from current Safari page to desktop (as .webloc file)

Alec Jacobson

August 13, 2009

weblog/

I like to hold onto web pages in an albeit clumsy way.

Drag url by favicon to desktop

I drag the url by the favicon onto my Desktop. Apple creates a .webloc file there, which I can later double-click on to reopen the page. My problem arises when I have so many windows I open that I can't even find the Desktop. I could push F11 after I've started dragging the URL, but why not script this whole operation.
tell application "Safari"
	set current_url to URL of front document
	set current_name to name of front document
end tell
tell application "Finder" to set webloc to make new internet location file to current_url at desktop with properties {name:current_name}
Note: Forgive that long last line, but I'd rather have it easier to paste than read (Script Editor does not handle broken up lines well). Note: These .webloc are also great as attachments in emails where long URLs often get broken up. According to http://www.fileinfo.com/extension/webloc these files are not universally open-able but widely accepted enough that accompanying a plain text URL in an email usually provides a safe bet of the recipient actually opening the page.