My personal information empire would be complete if I could syncronize devonthink with my del.icio.us bookmarks. This would probably be rather complicated to implement.
First it would need to be syncronize rather then import because I would need to update it periodically. Somehow devonthink would need to be able to track where bookmarks were kept in the dt database so that it wouldn’t duplicate them with a syncronize.
Second. What would maybe make the most sense would be to create a group for each tag and then populate it with the bookmarks associated with that tag. Then replicate those bookmarks that are in multiple tags/groups.
The reason this would be so awesome is that I would be able to search both databases simultaneously. If I was looking for something I’d saved on PocketPC for instance, I’d be able to find both bookmarks tagged with pocketpc and articles i’d saved in devonthink.
I know the del.icio.us api is available, which would be at least one step in the right direction.
Yes, that would be really great. My workaround for the meantime is subscribing in DT to my own del.icio.us RSS feed. So I can at least search titles and descriptions - not tags. And it’s not sorted, of course.
This is actually possible. If you use Delicious2Safari - macupdate.com/info.php/id/16095 - then your del.icio.us bookmarks will be added to your safari bookmarkts. From here it’s only a matter of importing your Safari bookmarks into DT. The only problem, is that you have to repeat the process on a regular basis (or write an applescript…i don’t know how to do that sadlly) to make sure the new ones are imported. What I was doing (I don’t have very good regular syncing/backup management habits) was deleting the safari folder in DT and then re-importing new each time. NOT a very elegant solution, but a solution nonetheless. If anyone has a brighter idea, let me know.
property pUser : ""
property pPassword : ""
tell application "DEVONthink Pro"
try
set theURLs to {}
set theNames to {}
set theXML to download markup from "http://del.icio.us/api/posts/all" user pUser password pPassword
if theXML is not "" then
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "href=\""}
set theHrefs to text items 2 thru -1 of theXML
set AppleScript's text item delimiters to "\""
repeat with theHref in theHrefs
set theURLs to theURLs & (text item 1 of theHref)
end repeat
set AppleScript's text item delimiters to "description=\""
set theDescriptions to text items 2 thru -1 of theXML
set AppleScript's text item delimiters to "\""
repeat with theDescription in theDescriptions
set theNames to theNames & (text item 1 of theDescription)
end repeat
set AppleScript's text item delimiters to od
if (count of theURLs) is equal to (count of theNames) then
set theGroup to create location "del.icio.us"
set theCnt to (count of theURLs)
repeat with i from 1 to theCnt
set theURL to (item i of theURLs)
set theName to (item i of theNames)
if not (exists record with URL theURL in theGroup) then
create record with {name:theName, type:nexus, URL:theURL} in theGroup
end if
end repeat
else
error "Unknown error."
end if
else
error "Download failed."
end if
on error error_message number error_number
if the error_number is not -128 then
try
display alert "DEVONtink Pro" 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
Note: You have to define the user & password properties at the beginning and then the script should be able to download your bookmarks (without creating duplicates) and to store them in the group “del.icio.us”.
Please let me know if it’s working - I don’t use del.icio.us and only created an account for testing with few bookmarks.
You are a GOD! That script works perfectly. This is the only forum I visit without having a problem first. It’s stuff like this that has made me a DT evangelist. I’ve already convinced two people at work to try out DT and they love it too. Now if only there was a PC version so that I can have DT in my office.
Some too long lines have been wrapped by the forum, for example the first wrapped line begins with “set theXML to download…”. You have to remove the line feeds and then it should work.
I was wrong - the forum just wraps the code to the window width, there are no additional line feeds. Therefore pasting this code to Apple’s Script Editor should work (at least if you’re using a WebKit based browser like Safari or DEVONagent).
Great, thank you. I wonder if it wouldn’t be too hard to include tags and/order description of a delicious item in the import - maybe importing it to the comments field of the DT-item.
Hi, I am another user od DT and del.icio.us, and I am so grateful for this script. I created an empty script and copied your code, but after starting the script from DT script menu, DT stops with error dialog: “The variable nexus is not defined” What am I doing wrong?
Christian, the script fails to put ‘theName’ correctly when the list ‘theDescription’ contains Unicode asian letters ( I have some Korean and Japanese links in my del.icio.us). I tried as follows, but with no luck at all.
...
set theNames to theNames & (text item 1 of theDescription) as Unicode text
...
Here’s an updated version of the script for DT Pro 1.1 specifying the right encoding for the downloaded XML file (del.icio.us doesn’t define the encoding of the XML file on its own) and therefore supporting non-ascii characters:
-- Import del.icio.us bookmarks
-- Created by Christian Grunenberg on Mon Jan 23 2006.
-- Copyright (c) 2006. All rights reserved.
property pUser : ""
property pPassword : ""
tell application "DEVONthink Pro"
try
set theURLs to {}
set theNames to {}
set theXML to download markup from "http://del.icio.us/api/posts/all" user pUser password pPassword encoding "UTF-8"
if theXML is not "" then
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "href=\""}
set theHrefs to text items 2 thru -1 of theXML
set AppleScript's text item delimiters to "\""
repeat with theHref in theHrefs
set theURLs to theURLs & (text item 1 of theHref)
end repeat
set AppleScript's text item delimiters to "description=\""
set theDescriptions to text items 2 thru -1 of theXML
set AppleScript's text item delimiters to "\""
repeat with theDescription in theDescriptions
set theNames to theNames & (text item 1 of theDescription)
end repeat
set AppleScript's text item delimiters to od
if (count of theURLs) is equal to (count of theNames) then
set theGroup to create location "del.icio.us"
set theCnt to (count of theURLs)
repeat with i from 1 to theCnt
set theURL to (item i of theURLs)
set theName to (item i of theNames)
if not (exists record with URL theURL in theGroup) then
create record with {name:theName, type:link, URL:theURL} in theGroup
end if
end repeat
else
error "Unknown error."
end if
else
error "Download failed."
end if
on error error_message number error_number
if the error_number is not -128 then
try
display alert "DEVONtink Pro" 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
The updated version goes beautiful. Thank you, Christian, as always.
For those who don’t want to put their username and password in plain text, you can replace the first two lines beginning with “property” in the updated version with the following code, on condition that you have del.icio.us internet keychain item in your keychain. For example, Cocoalicious creates this kind of keychain item. Or, you can create one with name “http://del.icio.us”.
--used the code from Trash Man at Macsripter BBS
tell application "Keychain Scripting"
set theKeyList to name of every Internet key of current keychain
repeat with x from 1 to (length of theKeyList)
if item x of theKeyList is "del.icio.us" then
set pUser to the account of Internet key x of current keychain
set pPassword to password of Internet key x of current keychain
exit repeat
end if
end repeat
end tell
Here’s a simplified version (which will only work if an Internet key named “del.icio.us” exists):
tell application "Keychain Scripting"
set theKey to first Internet key of current keychain whose name is "del.icio.us"
set pUser to account of theKey
set pPassword to password of theKey
end tell