Jump to content
dvcrn

Alfred -> DEVONthink

Recommended Posts

Posted (edited)

Super simple workflow for interacting with DEVONthink.

 

1437544415_ScreenShot2018-05-20at0_37_11.png.aa7fc246639f7971ab2b91299ad88fb8.png

 

Use

 

- `ds` to search DEVONthink
- `dn` to create a new DEVONthink note

 

Also defines a `Import To DEVONthink` file action to quickly add files from Alfred to the DEVONthink Inbox. (Very useful with the File Selection shortcut from Alfreds Features -> File Search -> Actions to instantly open the currently selected file in Alfred)

 

1036029490_ScreenShot2018-05-20at1_15_36.png.da2ccda42519662e25c4b39bbeb945bc.png

 

Get it here: https://github.com/dvcrn/alfred-devonthink/releases

 

This workflow will auto-update itself when a new version is available. If you don't want this, open the workflow and remove the "Auto Update" node. 

 

TODO:

- Global hotkey to paste whatever is in the clipboard to DEVONthink

 

If you have other cool ideas that would make DEVONthink with Alfred even more useful, please let me know :)

Edited by dvcrn

Share this post


Link to post

Hi dvcrn,

 

Thank you for this Workflow, but it doesn't work for me. I'm running most recent version of DTPro, and Alfred, on macOS 10.12.6

When I type ds, the Alred window shows "DevonThink Search", but when I type anything else, it reverts to a Google search.

Please advise.

 

Thanks,

Matthew

 

Share this post


Link to post

Hi, dvcrn,

 

Thanks for the good workflow, but I have the same issue with mlondon.

Have we missed something or can you explain how it works more clearly?

 

Thanks

Tommy Huang

Share this post


Link to post

Hi, dvcrn,

 

Now the workflow is working like charm!! So great to have this workflow!! 

Nothing was changes before it's working?! Strange but very happy!!

Thanks!

 

Tommy Huang

Share this post


Link to post
Posted (edited)

Whoops, I forgot to turn on email replies so I didn't see these comments until now - sorry about that! It's turned on now. 

Is everything working ok now? The search command is using the spotlight index to search for DEVONthink metadata files without much magic, so if spotlight is doing it's job fine, you should find them. 

 

I also just pushed an update to replace the import commands with applescript which should make the workflow a good chunk more robust :)

I also included a auto update script independent of packal (since that seems to be dead now anyway). Check the first post for the updated workflow (that will update itself from now on) 

Edited by dvcrn

Share this post


Link to post

This is fantastic! Thank you so much, I've really wanted a better way to interact with DEVONthink in Alfred, way better than just setting up a custom search!

 

As an aside, I really like the Alfred theme you're using, any chance you could post it?

Share this post


Link to post
3 hours ago, chrisWhite said:

This is fantastic! Thank you so much, I've really wanted a better way to interact with DEVONthink in Alfred, way better than just setting up a custom search!

 

As an aside, I really like the Alfred theme you're using, any chance you could post it?

 

The theme in the screenshot is The Minimalist. I use the 'almost midnight' variant

Share this post


Link to post

It seems all workflows for Devonthink can't search those materials to be indexed by Devonthink. 

If it can do this, please tell me how to make it work?

Alternatively, is there any way to set a hotkey to start the Search Window of Devonthink?

 

I think this hotkey function is enough to search everything contained in Devonthink.

Share this post


Link to post

You can use applescript to access DEVONthinks search, something like:

tell application id "com.devon-technologies.thinkpro2"
	search "foo"
end tell

You can integrate that into a alfred workflow but I didn't have the time to play around with that yet 

 

I'm not sure if it's possible to open a search window directly, but you could use keyboard maestro (or possibly UI scripting with applescript) to activate DEVONthink and execute the "search" menu action

Share this post


Link to post
16 hours ago, Kikuchiyo said:

Any thoughts on how to modify this workflow to open the file after creation?

You can expand the applescripts inside the workflow. `create record` should give you the record back it created. From there you can tell DEVONthink to open it and grab focus

Share this post


Link to post

Thanks, oddly I can't get DEVONthink to open the record. The following passes the debugger, but doesn't work.

	tell application id "DNtp"
		create record with {name:theQuery, type:text, content:theQuery} in inbox
		open theQuery
		activate
	end tell

 

Share this post


Link to post

Update: I made some progress based on this post

 

	tell application id "DNtp"
		set theRecord to create record with {name:theQuery, type:text, content:theQuery} in inbox
		set theFile to path of theRecord as POSIX file
		tell application "Finder" to open theFile
	end tell

It opens the files in apps that are set to handle the file type. In my case BBEdit. Not DEVONthink. I'm guessing because DEVONthink doesn't understand POSIX files?

Share this post


Link to post

I love the idea of this workflow, especially given that, for some reason, Spotlight includes DT items in its search results but Alfred doesn't...

 

One issue I have though, and I can't tell if it's my set up, but the search results of this workflow seem to be ordered by date created (maybe?) rather than relevance. In any case, when I do a search with two terms I know are part of the name of a DT item, this item is included in the results, but down the list. Other items that do have those terms somewhere in their content show up first.

 

Also, am I correct that it doesn't search DT tags? 

 

Thanks for your help!

Share this post


Link to post
8 hours ago, Kikuchiyo said:

Update: I made some progress based on this post

 


	tell application id "DNtp"
		set theRecord to create record with {name:theQuery, type:text, content:theQuery} in inbox
		set theFile to path of theRecord as POSIX file
		tell application "Finder" to open theFile
	end tell

It opens the files in apps that are set to handle the file type. In my case BBEdit. Not DEVONthink. I'm guessing because DEVONthink doesn't understand POSIX files?

 

You mean like this? 

 

tell application id "DNtp"
	set newRecord to create record with {name:"foo", type:text, content:"foo"} in inbox
	open window for record newRecord
	activate
end tell

This creates a document, opens it in a new editor window and sets focus to DEVONthink 

Edited by dvcrn

Share this post


Link to post
5 hours ago, gr37 said:

I love the idea of this workflow, especially given that, for some reason, Spotlight includes DT items in its search results but Alfred doesn't...

 

One issue I have though, and I can't tell if it's my set up, but the search results of this workflow seem to be ordered by date created (maybe?) rather than relevance. In any case, when I do a search with two terms I know are part of the name of a DT item, this item is included in the results, but down the list. Other items that do have those terms somewhere in their content show up first.

 

Also, am I correct that it doesn't search DT tags? 

 

Thanks for your help!

 

Yeah currently ordering seems a bit off since it's not using DEVONthinks engine for searching, but just spotlight. I want to change the search part to use DEVONthinks search applescript interface but didn't have time for that yet. And yes, tags are not searched yet. 

Share this post


Link to post

Just a heads up - I tried rewriting the search to use DEVONthinks search interface but it looks like that's restricted to the currently selected database if not specified. I was also not able to find a way to get a list with all open databases that could be usable for this so I'm throwing the towel for now. 

If anyone has an idea, let me know!

Share this post


Link to post

Would be awesome if you could figure it out, but isn't it the case that even Devonthink's own search bar doesn't search across all databases but just the one currently selected?

Share this post


Link to post

Looks like it's not that hard after all. Got a little proof of concept with the applescript interface working. 

It's not done yet but I'll try to get a update out this weekend / early next week ?

 

1679048572_ScreenShot2018-10-17at9_19_27.png.810ae61eee3ba984b95fa0154e1dc8af.png

Share this post


Link to post

awesome. 

Any chance this could also allow to include tags in the scope of the search?

Share this post


Link to post

I pushed an update (1.4.0) that uses the applescript search interface. It should auto-update but if it doesn't, get it here - https://github.com/dvcrn/alfred-devonthink/releases/tag/v1.4.0

 

Some caveats: 

- Sorting is a bit meh. There is a score field returned by DEVONthink but it's always 0 for me. I am currently just appending all results from each db

- With a lot of results, it's very slow. I limited it to max 10 per db for now which feels like a good sweet spot

 

Tags, I am not sure. It can search for tags, so maybe a separate tag search might make sense? 

 

I'l see if I can fix the sorting part somehow. 

 

2 other ideas that came up while adding this:

- Quick jump to a folder. DEVONthink doesn't have quick-jump functionality so Alfred could help out with that. Similar to how Safari Assistant does quick jump to open tabs

- Quick move to. Similar to Quick Jump: Select something, hit a shortcut, fuzzy find a folder and it'll move the item to that folder instantly 

Edited by dvcrn

Share this post


Link to post

Thanks! I tried it and, yeah, the sorting is strange. I typed a search with the exact name of an item, and it came 19th out of 20 results.

 

Nice to be able to search tags!

 

anyway we could specify what we search (e.g. tag:example or name:example, or kind:pdf, etc.) with AND OR, etc.?

 

Share this post


Link to post

Searching order right now works like this: It searches the first db, then the second, then the third and so on. After that, it just puts all the results into a big result list. 

Another idea was to merge them as is, so: first result of db1, first result of db2, first result of db3, etc but if your db doesn't have any good results it would just show really irrelevant things inside good results. 

 

Someone inside the devonthink forums just told me that 2.10.2 fixes the scoring being 0 problem, so I'll take a look at that later!

 

For what to search, the search interface itself currently only supports this:

 

1668787059_ScreenShot2018-10-27at10_09_27AM.png.0387f5eccc323f3983b6befb95c876e4.png

 

Everything else would have to get implemented through other means (like finding the tag, then searching in that tag group, then filtering inside alfred by kind)

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×