"Almost Rich-Text" Note from Firefox

Hi,

my primary browser is Firefox, thus I wrote an AppleScript which creates an “Almost Rich-Text” note from the current Firefox selection.

As of Firefox 3.5 (as far as I know), a copied selection from Firefox will be in HTML format, which will preserve all links, images and some rudimentary styling. This HTML record can be converted to RTF(D) to have an offline version of the entry with all images inside.

I hope you’ll find this script useful and if you have any problems just let me know.

(*
	Create almost rich text note from Firefox' clipboard
	Created by Patrick Mosby on Mar Wed 25 2009.
	Copyright (c) 2009. All rights reserved.
	
	
	How to use this script
	
	Select a portion of a website and invoke the script 
	with any of the varios methods like FastScripts, 
	Quicksilver, Launchbar, QuicKeys…
	
	All the links and rudimentary styling will be preserved.
	
	I haven't specified a destination for the 'newRecord' as I'm 
	using the new destination selector which will pop up as
	soon as you invoke the script.
	
	Tested only with Firefox 3.1b3 - 3.5 and DEVONthink Pro 2
*)

property theTitle : "(REPLACE THIS TEXT)"

tell application "Firefox"
	activate
	tell application "System Events" to keystroke "c" using command down
	try
		set theWindow to window 1
		set theTitle to the name of theWindow
	on error
		display dialog "Please provide a title:" default answer theTitle
		set theTitle to text returned of result
	end try
end tell

tell application "DEVONthink Pro"
	set newRecord to paste clipboard
	set theRichRecord to convert record newRecord in parent 1 of newRecord to rich
	set name of theRichRecord to theTitle
	delete record newRecord
	
	tell application "GrowlHelperApp"
		set the allNotificationsList to ¬
			{"Success Notification", "Failure Notification"}
		set the enabledNotificationsList to ¬
			{"Success Notification"}
		register as application ¬
			"Add to DEVONthink" all notifications allNotificationsList ¬
			default notifications enabledNotificationsList ¬
			icon of application "DEVONthink Pro"
		notify with name ¬
			"Success Notification" title ¬
			"Import Success" description ¬
			"Successfully imported" application name "Add to DEVONthink"
		notify with name ¬
			"Failure Notification" title ¬
			"Import Failure" description ¬
			"Alas — you won't see me until you enable me..." application name "Add to DEVONthink"
	end tell
end tell

P.S.: Feedback on how to improve this script is desired.

Nice script! The line “set theLocation to location of newRecord” is obsolete but everything else seems to be fine. Wonder if Firefox is going to support services and/or AppleScript some day. It’s a really poor Mac OS X citizen.

Thanks for the hint, I edited the script.

Firefox 3.6 will support Services but as far as I know it won’t support Rich Text.

Here’s the current version I’m using with Firefox 3.6pre and 3.7a1pre:

(*
	Create almost rich text note from Firefox' clipboard
	Created by Patrick Mosby on Jan Sat 16 2010.
	Copyright (c) 2010. All rights reserved.
	
	
	How to use this script
	
	Select a portion of a website and invoke the script 
	with any of the varios methods like FastScripts, 
	Quicksilver, Launchbar, QuicKeys…
	
	All the links and rudimentary styling will be preserved.
	
	I haven't specified a destination for the 'newRecord' as I'm 
	using the new destination selector which will pop up as
	soon as you invoke the script.
	
	Tested with Firefox 3.1b3 - 3.7a1pre and DEVONthink Pro 2
*)

-- property theTitle : "(REPLACE THIS TEXT)"

tell application "Namoroka"
	activate
	tell application "System Events"
		keystroke "c" using command down
	end tell
end tell

tell application "DEVONthink Pro"
	set newRecord to paste clipboard
	set theLocation to location of newRecord
	set theRichRecord to convert record newRecord in parent 1 of newRecord to rich
	set name of theRichRecord to name of newRecord
	delete record newRecord
	
	tell application "GrowlHelperApp"
		set the allNotificationsList to ¬
			{"Success Notification", "Failure Notification"}
		set the enabledNotificationsList to ¬
			{"Success Notification"}
		register as application ¬
			"Add to DEVONthink" all notifications allNotificationsList ¬
			default notifications enabledNotificationsList ¬
			icon of application "DEVONthink Pro"
		notify with name ¬
			"Success Notification" title ¬
			"Import Success" description ¬
			"Successfully imported" application name "Add to DEVONthink"
		notify with name ¬
			"Failure Notification" title ¬
			"Import Failure" description ¬
			"Alas — you won't see me until you enable me..." application name "Add to DEVONthink"
	end tell
	
	do shell script "afplay /System/Library/Sounds/Glass.aiff"
end tell