Archive Firefox URL to specific Database

I am using the script below to archive the current Firefox URL to DT, but the script is unfortunately configured to archive the URL to whatever database happens to be open at the moment, and if none are open, then it will open the database that I’ve specified as the ‘Default DT Dtatabase’ within the DT preferences, and then it will archive the URL to that database…

I was hoping that someone might be able to respond back with a modified version of the script below that will archive the current firefox URL to a particular database…specifically:

Database Name: Tech Database.dtBase
Database Path: HD1:DEVONthink Pro Database:Tech Database.dtBase

Not sure if its the default behavior of the program, or if any additional customization would need to be done, to first close any currently opened DT database (that isn’t the one specified above) before opening the specific database I want to archive firefox URLs to - but in case that’s not the default behavior, I would of course need the script setup to do this…

Any help with this would be greatly appreciated…Thanks!

tell application "GrowlHelperApp"
	-- Make a list of all the notification types
	-- that this script will ever send:
	set the allNotificationsList to ¬
		{"Add webarchive"}
	-- Make a list of the notifications
	-- that will be enabled by default.     
	-- Those not enabled by default can be enabled later
	-- in the 'Applications' tab of the growl prefpane.
	set the enabledNotificationsList to ¬
		{"Add webarchive"}
	-- Register our script with growl.
	-- You can optionally (as here) set a default icon
	-- for this script's notifications.
	register as application ¬
		"WebImporter" all notifications allNotificationsList ¬
		default notifications enabledNotificationsList ¬
		icon of application "DEVONthink Pro"
end tell

on getCurrentURL()
	tell application "System Events"
		set myApp to name of first application process whose frontmost is true
		if myApp is "Camino" then
			-- tell application "Camino"
			-- URL of window 1
			-- end tell
		else if myApp is "firefox-bin" then
			tell application "Firefox"
				«class curl» of window 1
			end tell
		else if myApp is "Safari" then
			tell application "Safari"
				URL of document 1
			end tell
		else if myApp is "Opera" then
			-- tell application "Opera"
			-- set myInfo to GetWindowInfo of window 1
			-- item 1 of myInfo
			-- end tell
		end if
	end tell
end getCurrentURL

tell application "DEVONthink Pro"
	set this_url to my getCurrentURL()
	display dialog this_url
	set theArchive to create record with {name:this_url, type:html, URL:this_url} ¬
		in incoming group
		with timeout of 60 seconds
			set data of theArchive to download web archive from this_url
				set this_source to source of theArchive
				if this_source is not missing value then
					set this_title to get title of this_source
					if this_title is not missing value and this_title is not "" then
						set the name of theArchive to this_title
					end if
				end if
			end try
		end timeout
		tell application "GrowlHelperApp"
			notify with name "Add webarchive" title this_title ¬
				description "Added to DEVONthink Pro" application name "WebImporter"
		end tell
	on error msg
		tell application "GrowlHelperApp"
			notify with name "Add webarchive" title this_title description msg ¬
				application name "WebImporter"
		end tell
	end try
end tell


A little help with this would be appreciated beyond belief!


Just insert…

open database "/Volumes/HD1/DEVONthink Pro Database/Tech Database.dtBase"

…after ‘tell application “DEVONthink Pro”’. Opens the specified database if necessary and closes the current database.

Thanks for the tip…

That did work, but one problem I still have is that it only works (i.e. opens the correct database to add the web archive to) if DT is not open when the script is triggered…If DT is opened and has a different database open when triggering the script, the code you provided doesn’t seem to work, as it simply proceeds with adding the web archive to the currently opened database…

Is there any way to supplement the bit of code you provided with something that first checks to see if the correct database is open, and if its not, then to close whatever database is open, and subsequently opening the new one to add the web archive to?

Any suggestions would be greatly appreciated… Thanks!

Some AppleScript commands are executed asynchronously, you might try to add a delay (e.g. “delay 1”) after the “open database” command.