Hello! I’m looking forward Devonthink as a companion to or even the complete replacement of Evernote. My Evernote flow includes a lot of attachments and internal links across notes.
The Devonthink’s embedded import routine handled the most of my notebooks well, yet always get stuck after import of a single huge notebook with a lot of notes. So, I’ve managed to import this one by processing of small chunks of ENEX export packages.
Because internal links are the crucial part of my workflow, I use an apple script to embed Evernote internal links in URL filed of every note. Thus, all notes imported to the Devonthink no matter which way already do have their own local Evernote link in their URL field embedded.
Now I’ve got to:
(i) for every note in main database,
(ii) and if it contains any internal links in text (e.g., links referring to path starting with “evernote://etc”),
(iii) find another note with text, that has the same URL in URL field and is of type “formatted note” and copy internal link to it,
(iv) replace the original reference of the link with the new one.
Step (iii) has additional complications, because a note with non-image attachments becomes a group consisting of a text note that has the same name as the group and attached files separately. And every child of such group has the same internal Evernote URL in its URL field. Thus step (iii) must include an additional mechanism that finds the note with text (not an attachment file). On my opinion the easiest way to do this is to test whether a record with correct URL is of type “formatted note” (all Evernote imports with text have this type).
I’m a developer myself but I’m not used to apple script dictionary syntax. I’ve tried to write the script myself, and this is what I’ve got so far:
using terms from application "DEVONthink 3" tell application "DEVONthink 3" try # (i) for every record in db check if record is formatted note set recs to a reference to contents of current database repeat with rec1 in recs if ((type of rec1) as text) is "formatted note" then log message (name of rec1) as text # (ii) if record contains links starting with "evernote://" set chunks to attribute run of rich text of rec1 repeat with chunk in chunks if (URL of chunk) is not null then # ERROR: Can't get URL of "_my note text without link is here_" log message (URL of chunk) as text if URL of chunk starts with "evernote://" then if exists record with URL (URL of chunk) in current database then set recs2 to lookup records with URL in current database # (iii) for every record2 in db if type of record2 is correct repeat with rec2 in recs2 if type of rec is "formatted note" then # (iv) check local link of record2 and replace with it the old one set url2 to URL of record2 if url2 is equal to URL of chunk then log message ((URL of chunk) as text) & " got to be replaced with " & ((reference URL of rec2) as text) # set URL of chunk to reference URL of rec2 end if end if end repeat end if end if end if end repeat end if end repeat on error error_message number error_number if the error_number is not -128 then display alert "DEVONthink 3" message error_message as warning end if end try end tell end using terms from
An error occurs at the line “if (URL of chunk) is not null then”. I’ve tried a lot of options instead of null but can’t figure out how to test if a chunk of rich text has an active URL property.
Any help to finish this script it will be highly appreciated!