The following script will work for all browsers. I recommend using FastScripts Lite (an excellent, free product) for binding this script to Cmd-I in all of your browsers.
It will save the current page as a webarchive in your DEVONthink – in the background – and then display a Growl notification on successful completion.
Uncomment the Camino and/or Opera sections if you use those browsers. If you use OmniWeb, replace the word Safari in the following script to OmniWeb.
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
else
return
end if
end tell
end getCurrentURL
tell application "DEVONthink Pro"
set this_url to my getCurrentURL()
set theArchive to create record with {name:this_url, type:html, URL:this_url} ¬
in incoming group
try
with timeout of 60 seconds
set data of theArchive to download web archive from this_url
try
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
Hmmm…doesn’t seem to be working for me in Firefox. Copied and pasted your code into Apple Script Editor, saved it to my User Scripts Folder, but when I invoke it using the drop-down script menu in my menu bar (on the right), nothing happens. I must be doing something wrong? Hope I can get it to work as this script is exactly what I’ve been looking for…
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
else
return
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
try
with timeout of 60 seconds
set data of theArchive to download web archive from this_url
try
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
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
try
with timeout of 60 seconds
set data of theArchive to download web archive from this_url
try
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
If i put the “got here!” command immediately after this, i don’t see it. If I put “got here!” immediately before this section, I do see it.
This is a great script.
The use of growl is inspired as is the FastScripts suggestion.
In order to allow saving to the current rather than the new notes group change last line in
tell application "DEVONthink Pro"
set this_url to my getCurrentURL()
set theArchive to create record with {name:this_url, type:html, URL:this_url} ¬
in incoming group
to
tell application "DEVONthink Pro"
set this_url to my getCurrentURL()
set theArchive to create record with {name:this_url, type:html, URL:this_url} ¬
in current group
The web archive should appear in the current group.
I use both this modified and the original script bound to Cmd-I and Cmd-opt-I. In this way I can send either to the new notes or current group.
Note that this script does not switch the app context bringing DT to the fore like some scripts tend to. I’m not sure if this is a consequence of the FastScripts context switching detection abilities or not.
It would be good to be able to trigger the script with the mouse off the menu or toolbars. Any suggestions on this?
Forgive the newbie question, but what would this look like with a line “uncommented”?
I cannot get this to work with either Firefox or Omniweb (haven’t tried another browser). Looks like I’m having the “same issue” as a previous poster.
I don’t see anything being invoked in the console.
A commented line in AppleScript begins with –
Therefore, to activate the code for camino and opera the code segment becomes:
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
else
return
end if
end tell
end getCurrentURL