Option to open certain document types directly in external editor

I would find it very useful if I could configure certain document types (e.g. markdown) to open directly in my editor of preference by default, rather than opening in the DevonThink editor.

To provide a bit of context, I write everything in Markdown and never use the DevonThink editor for that. When I remember to select and press Shift+Cmd+O, I can do this in the DT UI, but when I’m following a document link using “x-devonthink-item://”, it always opens the DT editor.

2 Likes

Welcome @dt101

Sorry but no, that will not work. A URL scheme is not going to open an application that it doesn’t belong to.

Add to the end of all DT links you use “?reveal=1”, and DT will just open the location and select the item, you will only have to hit Shft+Cmd+O.

2 Likes

Thanks for the reply. I’m not suggesting that a URL would launch an app other than DT. I realize that’s not possible. Perhaps my use of the word “directly” made things confusing.

What I am proposing is that, for configured file types, DT would “launch” the document (Shift+Cmd+O) instead of opening the document in its own internal editor (Cmd+O).

I’ve written some AppleScript that demonstrates how I envision this would work (hopefully the formatting gets through OK):

on user_followed_url(theUrl)
    -- Extract UUID from URL
    set theDefaultDelimiters to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "://"
    set theUUID to text item 2 of theUrl
    set AppleScript's text item delimiters to theDefaultDelimiters
    
    tell application "DEVONthink 3"
        -- get the record and its filesystem path
        set theRecord to get record with uuid theUUID
        set thePath to path of theRecord
        
        --- determine how to open the document
        if thePath ends with ".md" then -- TODO: specific file types configurable via preferences
            tell application "Finder"
                open (POSIX file thePath as alias)
            end tell
        else
            open window for record theRecord
        end if
    end tell
end user_followed_url

Now, pretend the spirit of this code was integrated into DT. Clicking a URL would still activate DT, but DT would decide what to do next based on file type. The user would probably see DT activate for a split second before ending up in the document’s external application. Technically, I suppose DevonThink would be acting as a proxy for opening the document in its default application.

2 Likes

Thanks for this tip. That gets me most of the way there and eliminates the leftover windows, which is probably the biggest annoyance for me.

This is a good work-around, but the ideia of being able to do it directly isn’t bad either. If I am not mistaken, this what Hook does (amongst other things I imagine).

There is an Alfred Workflow I use to get around my main database more quickly. Inspired by this thread, I just added the option to open records externally. Not exactly what was being requested here, but perhaps it can be useful. The only downside is that you have to manually get the links for the records and drop them as a CSV unto the Alfred list filter.

There is also this workflow to search DT3 that has the option to open records externally as well:

To have it as an option in Devonthik would be great!

I find Launchbar invaluable for this; from a DEVONthink window with items selected, ‘instant send’ them to Launchbar, then press ⇥ and choose what to launch with, or press :leftwards_arrow_with_hook: to open with the default file handler as registered in Finder (or Launchbar!)

Best you can hope for is a workaround using Applescript, Alfred of LaunchBar.

@Bernardo_V I like your idea and wanted to take a look at your Wiki - Dummy.alfredworkflow, but Dropbox says that it has since been deleted. Would it be possible for you to make it available again? Cheers!