I’ve written a couple of scripts for integrating the bookmark manager WebnoteHappy with DEVONthink Pro. They are somewhat basic, but suit my needs. I based these scripts on the example scripts created by Christian Grunenberg. Though any bugs are mine!
One script adds links from Webnote Happy to the current group in DEVONthink Pro, the other creates web archives from selected links.
The scripts are best placed in ~/Library/Scripts/Applications/WebnoteHappy, and accessed via the Apple script menu.
Create links -
-- Create Links From Selected Notes
tell application "WebnoteHappy"
try
set theSelection to {}
set theSelection to selection
if theSelection is not equal to {} then
repeat with theWebnote in theSelection
set theURL to url of theWebnote
set theTitle to title of theWebnote
set theTags to tags of theWebnote
set thisWhen to creationDate of theWebnote
-- Handle webnote with no tags
try
count of theTags
on error
set theTags to ""
end try
if (count of theTags) is not 0 then
set theTags to my replaceChars(theTags, " ", ", ")
end if
set theTags to "@tags: " & theTags
-- Add link to DEVONthink
tell application "DEVONthink Pro" to create record with {name:theTitle, date:thisWhen, type:link, URL:theURL, comment:theTags}
end repeat
else
error "No webnotes selected."
end if
on error error_message number error_number
if the error_number is not -128 then
-- -128 is "user cancelled"
try
display alert "Webnotehappy" message error_message as warning
on error number error_number
if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
end try
end if
end try
end tell
-- Replaces characters in a string
on replaceChars(a_string, old_item, new_item)
set theFix to AppleScript's text item delimiters
set AppleScript's text item delimiters to the old_item
set the item_list to every text item of a_string
set AppleScript's text item delimiters to the new_item
set a_string to the item_list as string
set AppleScript's text item delimiters to theFix
return a_string
end replaceChars
Create Webarchives -
-- Create Webarchives from Selected Notes
tell application "WebnoteHappy"
try
set theSelection to {}
set theSelection to selection
if theSelection is not equal to {} then
repeat with theWebnote in theSelection
set theURL to url of theWebnote
set theTitle to title of theWebnote
set theTags to tags of theWebnote
set thisWhen to creationDate of theWebnote
-- Handle webnote with no tags
try
count of theTags
on error
set theTags to ""
end try
if (count of theTags) is not 0 then
set theTags to my replaceChars(theTags, " ", ", ")
end if
set theTags to "@tags: " & theTags
-- Add webarchive to DEVONthink
tell application "DEVONthink Pro"
set theArchive to create record with {name:theTitle, type:html, date:thisWhen, URL:theURL, comment:theTags}
set data of theArchive to download web archive from theURL
end tell
end repeat
else
error "No webnotes selected."
end if
on error error_message number error_number
if the error_number is not -128 then
-- -128 is "user cancelled"
try
display alert "Webnotehappy" message error_message as warning
on error number error_number
if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
end try
end if
end try
end tell
-- Replaces characters in a string
on replaceChars(a_string, old_item, new_item)
set theFix to AppleScript's text item delimiters
set AppleScript's text item delimiters to the old_item
set the item_list to every text item of a_string
set AppleScript's text item delimiters to the new_item
set a_string to the item_list as string
set AppleScript's text item delimiters to theFix
return a_string
end replaceChars