dear all,
Here’s a hacked together script with very little error checking that nonetheless seems to save a lot of time for me. It captures all links on the current page to webarchives. It is a great thing if you need to suck down a bunch of pages, but don’t like the archive system. give it a try and tell me what you think…
erico
-- webarchive all links 1.0
-- Created by Eric Oberle, shameless borrowing code snippets from Christian Grunenburg
---When you run this script, it will seek to create webarchives of all links on the currently selected page. It will put these archives in a folder in the current group, named according to the title of the current web page. This script is very handy for
-- I should probably turn this into two scripts. One that downloads all links to a separate subfolder of current. Second that turns all links in current folder into webarchives.
tell application "DEVONthink Pro"
activate
try
set current_selection to selection of viewer window 1
set current_group to current group
set include_string to ""
if not (exists window 1) then error "No window is open."
set original_url to the URL of window 1
set this_source to the source of window 1
set include_query to display dialog "Please type phrase that all desired links contain, or press return for all " default answer "" buttons {"continue", "cancel"} default button "continue"
if (text returned of include_query is not "") then
set include_string to (text returned of include_query)
set these_links to get links of this_source base URL original_url containing include_string
set temp_folder_name to include_string & " links "
else
set these_links to get links of this_source base URL original_url
set temp_folder_name to the name of viewer window 1
end if
set dest_group to create record with {name:temp_folder_name, type:group} in current_group
set this_title to (the name of viewer window 1)
repeat with this_link in these_links
if not (exists record with URL this_link) then
with timeout of 120 seconds
set theRecord to create record with {name:this_title, type:link, URL:this_link} in dest_group
set theWindow to open window for record theRecord
repeat while loading of theWindow
delay 1
end repeat
set theURL to URL of theWindow
set theSource to source of theWindow
set theName to get title of theSource
set theData to web archive of theWindow
set theArchive to create record with {name:theName, type:html, URL:theURL} in dest_group
set data of theArchive to theData
set source of theArchive to theSource
delete record theRecord -- Closes window
end timeout
end if
end repeat
on error the error_message number the error_number
if the error_number is not -128 then
display dialog the error_message buttons {"OK"} default button 1
else
error number -128
end if
end try
end tell