Alfred Extension: DEVONthink Note

Hey everybody! I spent the morning throwing together a slight modification to the wonderful houthakker’s Keyboard Maestro macro for adding a quick note to DEVONthink. This version of the script works with Alfred, a robust sort of a Spotlight replacement for OS X. If you’re a PowerPack user, you can download the extension here and double-click to install it.

I’m happy to answer questions and make changes and all that—like I said, I just sorta threw it together. I’m trying to get DT and Alfred to play as nicely together as I possibly can, so if you have any other ideas for things you wish you could get DEVONthink to do with a keystroke, let me know! Up next are import (definitely) and search (maybe).

Updates
Updated 12/02/2012 so that the extension updater works properly and groups are created on the fly.
Updated 11/28/2012 to support the Alfred extension updater.
Updated 11/27/2012 to fix the logic that tried to send notes to the Inbox. It should actually work as expected now.

Installing
Download the extension here and double-click to import to Alfred.

Usage
By default, the extension is set up to respond to the keyword dtn. It accepts a query in the form of:


Title: The content of the note | Group

…and creates, then opens, a plaintext DEVONthink note with the content you’ve entered in the group you’ve entered. It will also accept less specific input—for example,


dtn The content of the note

will simply create a note with a dated boilerplate title in your Inbox. If you specify a group that does not currently exist, the script will try to create one in your current database—however, bear in mind that this can work unpredictably if DEVONthink is not running when the script is activated.

I can’t get it to work when I use the less-specific example you provided above. For example, with when I type “dtn The content of the note” nothing happens. Am I doing something wrong?

It certainly doesn’t look as though you are. I wonder if I changed something in the script and didn’t upload a new version. Try the extension attached to this post, which is working as expected on my machine, and let me know if it works.
DEVONthink Note.alfredextension.zip (16.4 KB)

It’s still not working for me. It doesn’t work unless I specify a group. It works without the title but not without the group. Also, the group name already needs to exist for it to work. It would be cool if it can create a group when it doesn’t find a match.

That’s awfully strange! I’ll keep trying to reproduce it; in the meantime, if you’re really gung-ho about getting it to work, you could try running the script from the command line to see if it’s throwing up an error. Open a Terminal window and type:


cd ~/Library/Application\ Support/Alfred/extensions/scripts/DEVONthink\ Note

If you’re not using the default name, replace “DEVONthink Note” with yours. Now run:


osascript devonthinknote.applescript "The content of the note"

…and post what it returns.

Sorry this didn’t just WORK for you! Hopefully you’ll get a useful little error from that Terminal command.

I totally agree that it would be nice for it to create a group if it can’t find one, and I’ll definitely look into doing that after finals. I glanced at the AppleScript Dictionary and didn’t see any promising hints, but where there’s a will….

Works for me! Thanks VERY much!

When I did this on the Terminal Window I got the following error:


execution error: DEVONthink Pro got an error: Can’t get parent 1 of database id 1 whose name = "Inbox". Invalid index. (-1719)

I, then, realized that the applescript had the Database labelled as “Inbox” and I had a different name. After I managed to change it, it started working for me.

Thanks a lot for your help. I use Alfred and DT a lot so this is an great extension for me.

Thanks for going to the trouble! That was very helpful information. I went back and redid the very jank, hacky way that I was trying to find an Inbox so that unless I’m much mistaken it now definitely defaults (jankily, hackily, but intelligently) to the global one. Though it still doesn’t create a group if you specify one that doesn’t exist, it now also, instead of just failing outright, sends the note to the global Inbox. You can download the updated version here and, now, structure your database as the spirit moves you.

I’ve updated the extension to support Alfred’s extension updater, so that you’ll be able to see and follow any changes to the extension without constantly checking this thread. I’ve also posted the usage information to static.daniel.sh/alfred/ (along with an extension for opening things in Sublime Text 2, if that takes your fancy). Download the updated version here.

Thanks for the update. It’s definitely more useful now, I don’t have to worry about selecting a group that doesn’t exist. It’s also working with global Inbox now.

Glad to hear it! I think you’ll be pleased to know that I’ve also added on-the-fly group creation. If you input a group that can’t be matched, the script will now try to create one in the current database. The name of the group can take the form of a path relative to the database root, so that you could tell it to create new group “Foo” under the group “Projects” by entering “Projects/Foo.” “Projects” will also be created if it can’t be found.

I’m finding that it’s a little unpredictable if DEVONthink isn’t running when it tries to create a new group; if this becomes more than a slight irritation, let me know and I’ll block the feature when Dt is closed.

The update code, which I broke by failing to un-“smarten” its quotes after a copy-and-paste, has also been fixed. Though I’m linking to a complete package here, the extension updater should find and install a dummy update when you query it (after updating manually from the web page).

Download the updated extension here, and let me know how it works for you! There’s also a new extension to facilitate SCP operations on that page.

It’s working perfectly for me. I use only a single database so I haven’t experienced any problems when DT is closed. But I just tested to see what happens with multiple databses and when DT is closed, it’s going into the last database (the one at the bottom). But I have no problems with freezing or anything like that.

I also noticed something odd. If there are two groups “cs” and “macs” and the latter is below the former, when you type “cs” for the group it goes into “macs.” It’s not a big deal, I only found it when I was randomly creating groups to test the extension. Just wanted to let you know in case you weren’t aware.

Fabulous! Although now I’m inclined to wonder why it is freezing on my machine.

I hadn’t noticed that little oddity with group selection, but I can see why it’s happening. The script looks for groups whose names contain the string that’s passed to Alfred, rather than for exact matches, and lower-level groups tend to be matched first. The partial-name matching makes less sense now that it can create new groups, though, so I could do away with it.

I’m also wondering if it wouldn’t make more sense for new groups to be created in the global Inbox when DEVONthink isn’t running. That seems like a more natural place to look for new input than the bottom-most database.

Hello, all! I was waiting to update this till the new beta of Alfred went into testing; it has, and so I have. It’s now an Alfred v2 Workflow rather than an Alfred v1 Extension, so you’d need to update your version of Alfred to use it. The interface is much less confusing and strange, as you can see from the screenshot below: with Alfred’s new Feedback system for Workflows, you can navigate through your databases and find the group you’re looking for, then enter a space and start typing your note. If it’s much in demand, I’ll add things like favorite groups. But it’s hot off the hard drive and ready for testing in its current form now if you’ve got a copy of Alfred 2.

Download it here or through AlfPT, and let me know how it works!

A beautiful piece of work - I’m using it in Alfred 2 – many thanks !

(With a FoldingText format for the opening template)

Sorry, I’m too thick to follow instructions.

Step 1

and then press space and type the text

press enter. Nix. Nothing created anywhere.

but it’s building a menu with the names of the (failed) notes (I don’t have databases named “Test Sep 8” or “2012 @ 11-55 AM”)

What :question:

Not at all! That was definitely a problem with the AppleScript. I didn’t test it with the Inbox, foolishly, since that’s the most logical place for quick notes to go. I think I’ve corrected the problem, and I’ve updated the AlfPT version and the version at this link.

I’m not sure why the script filter would be returning all those bad notes, though; it wasn’t responding the same way on my machine, even when I made a whole slew of failed attempts. With any luck it’ll just not be an issue now that the AppleScript is fixed, but please let me know if it stays broken.

Thank you! I’m pleased indeed that you’re getting some use out of it. How did you integrate FoldingText? I’m a big fan of that myself, so if there’s a way to work it in then I’d be eager to hear it.

Hey all. Just a heads-up that I’ve totally rewritten this workflow, and made some major changes. In addition to being automatically updatable with the Alleyoop workflow, it now handles things like commas and UTF-8 characters in database and group names much better, runs much faster, and generally stinks a lot less. You can download the updated version here: http://alfred.daniel.sh/Workflows/DEVONthinkNote.alfredworkflow . I’m mondo-grateful to our very own korm for helping me debug a lot of stuff in the last version, and to Jaemok for suggesting a fix for Unicode issues.

Oh, and no more need to enter a silly space before typing your note. Just navigate to the group you want and have at it.

Daniel, this is great. And AlleyOop comes along at just the right time … maybe Andrew & Vero will soon include this concept in baseline Alfred.