Devonthink, scripted

Busy with administrative, research and teaching matters, but I managed to carve out small bits of time late at night to tweak Devonthink with some Applescript and Keyboard Maestro. Mostly code monkey stuff, with the assistance of my programming wife, but helpful nonetheless. Don’t continue reading unless Devonthink, Applescript and macros get you excited.So what have I (we) done?

Slightly modified a script from the DT forum that automatically parses a document paragraph by paragraph, creating a new document for each paragraph, naming it after the first line. Made three versions for maximum flexibility: one generic command to split a document, when I have a bunch of random notes I want split and will delete the original when I’m done; another command to split a document and automatically insert a link back to the original for each new document, when I want to keep the original but also have it parsed; and the original forum script that parses each paragraph to a new document, but adds a number to the name of each to keep the order in which each appeared – useful, for example, if you are parsing a single source, or notes on one when the notes are in a particular order that needs to be retained.

Make Index to clipboard. Another useful code snippet from the forum. Select as many records as you want, and it will copy links of all of them to the clipboard in a list. Create a new document, paste, and you’ve got yourself a handy wiki-linked table of contents. (I probably should be able to do the last part with code too.)

Name to Spotlight. Combined a few pre-existing scripts to copy the name of the file to the Spotlight Comments of that file. This results from the fact that most of my files are imported in with the source info in the title. Since I actually want the Spotlight Comments for the title of the source (so I can rename the title to something more substantive), this saves a lot of typing.

Name to Tag. Since I continue to use tags for the provenance info, this code just copies the title to a new tag, which I can then move to wherever in the tag hierarchy I need it.

My pièce de résistance: just got Keyboard Maestro (a sophisticated macro program) and created an 11-step macro to move my French-language documents out of my English-language WSS database. You may recall, DT’s AI only works with a single language, so I created separate databases for each language. But I have notes where letters in different languages alternate – I need to first parse those into separate notes. And I have notes in French that I want the gist of in English, to use DT’s AI on in the English-language WSS database. But since I don’t want to solely rely on my translations, my English-language note should also include a link to the original French-language note, after it’s been moved to the French database. This will also allow DT’s AI to use the French language in the French database. So I first parse those notes, and then run the macro. It duplicates the record, copies the item link of the original French-language note and pastes it into the top of the copy (that will stay in the WSS). It then moves what will be the French original to a temporary holding group that will eventually be moved over to the French database. After a night’s work I couldn’t figure out the last stage, moving the record, but someone fortuitously just posted exactly the Applescript I needed on DT’s forum. I’ll still need to either delete or paraphrase the French-language note that remains in the WSS database into English, but it’s still saving me 11 steps for every record.

The takeaway? Don’t be afraid to play around with Applescript and macros – they can reduce a lot of the tedium. Another lesson: Devonthink’s Scripting forum has lots of useful code, but it takes some time to find them. It’s particularly challenging to know what to search under. For example, the parsing script described above can be found by searching for “explode”. I tend to reserve that verb for a more literal application, but I am a military historian after all.