Can CMD-O open in edit and click show preview?

Is it possible that when I press CMD-O on a MD document it opens in edit mode BUT when I click on it (in standard preview view) it shows the MD preview?

I have option Markdown Display set to Preview Documents. CMD-O also opens as preview.

In Karabiner-Elements, it should be possible to create a custom keyboard rule which does the following:

  • When DEVONthink is the active application, If your press ⌘O twice within a short timespan, the second ⌘O will be executed as ⌃⌘X instead.

I don’t use KE myself, so can’t provide more information on how to accomplish that.

A similar approach might be possible with other apps, eg Keyboard Maestro or Better Touch Tool.

I will investigate. Thanks.

@saltlane Just to give you an idea of what this could look like in BetterTouchTool.

⌘ + O is executed if no other key is pressed within 0.2 seconds.

⌘ + O + O is executed if the pause after the first O is shorter than 0.2 seconds.

This is an example, you can do it in different ways :slight_smile:

Yes, that too.

FYI - I tried using Keyboard Maestro (KM) but unfortunately setting for double tap CMD-O it blocks the single tap CMD-O.

Temporarily I have set KM so ALT-O executes CMD-O followed by CTRL-CMD-X. It has the added bonus that on other file types you can switch between best alternative and text alternative depending on if you type CMD-O or ALT-O.

I will play more. It may be better just to get used to typing CTRL-CMD-X :slightly_smiling_face:

I don’t know KM that well. But I think there are trigger options “is tapped only once” etc. So that should actually work, no?

Ah, but wait, looking at your macro, I’m not sure what you want to do. A cycle action? Or should the two shortcuts be executed one after the other?

This works for me.

Thanks. I tried this, but it does funny things if opening other document types. I couldn’t workout how to limit it for MD docs only.

For some documents types Ctrl-CMD-X sets them to text alternative view.

Try this. It should work for just MD.

… and also HTML and WebArchive.

In the end UI scripting is probably the simplest approach. No keyboard app required.

try
	tell application id "DNtp"
		activate
		set theRecord to item 1 of selected records
		if type of theRecord is markdown then
			open tab for record theRecord -- optionally, `in think window 1`
		else
			return
		end if
		delay 0.2
	end tell
	tell application "System Events"
		tell process "DEVONthink 3"
			click menu item "Source" of menu 1 of menu item "Document Display" of menu 1 of menu bar item "View" of menu bar 1
		end tell
	end tell
end try

Assign a custom keyboard shortcut to this script, and it’s good to go.

UI scripting is known to be fragile and unreliable. YMMV

1 Like

Indeed, though it’s perhaps not more fragile than keyboard macros; I assume the KM action for clicking menu item in @TonyLim 's screenshot is essentially a wrapper for System Events.

So, my previous request again: Can we get direct scripting control for the document views? :blush:

That’s not a decision I can make. And scripting the interface of an application is often the wrong idea as can lead to Rube Goldergian machinations. Scripting isn’t for creating an automoton; it is for creating actions and reactions in a process. It’s more akin to chemistry than robotics.

However, the request is (still) noted.

1 Like

That’s a good point, although I feel insistence on “cleanness” can be a red herring for developers. Fewer customization opportunities (scripting and settings), IMHO, do not reduce the variety of needs of the user.

We already have open window for and open tab for, in DT and other applications as well. I take that as an indication that there is indeed a need — an appreciated one — for controlling the appearance of user data through automation.

Anyway, thanks for considering. Have a good day.

Did you set up both macros?

AND

I’m afraid that’s not possible. KM would have to recognize where the cursor is currently located or what is currently being selected. It also doesn’t work with the names of text fields, because the fields have the same name.

Edit: If your MD docs have something unique in their name, for example “MD” :joy:, then you can create a condition.

  • If name contains “MD” → do that
  • If name does not contain “MD” → do something else

Something like this. But I don’t really understand KM.

Yes I did set up both. Thanks.

The problem is that KM can’t see into the future so doesn’t know you are going to double tap and always executes the single CMD-O routine. The double tap never gets executed (in my tests anyway).

That’s a good point, although I feel insistence on “cleanness” can be a red herring for developers.
Fewer customization opportunities (scripting and settings), IMHO, do not reduce the variety of needs of the user.

I don’t believe it’s about “cleanness”.
The problem is when the user believes they need something they don’t. For example, it’s not uncommon for people to look for commands to click buttons. Or they think things like, “I need a script to double-click on this group then select all the text documents in it then press the Merge command in the Tools menu, because that’s what I do every week.” Those are not actions a script should, or needs to, take. Again, it’s not about building a robot to push the buttons for you. Extending UI scripting reinforces the misunderstanding of what automation is.

PS: This one-liner (not necessarily recommended but quick for me to protoype and iterate on), essentially fulfills the example action mentioned above…

tell application id "DNtp" to set bounds of (open tab for record (merge records (children of (get record at "/Text/Files/Plain text/" in database "File Types") whose (type is txt))))'s think window to {350, 0, 1100, 800}

No group double-clicking group. No selecting documents. No button clicking. And it even opens the resulting document in a new document window, without having to “…find and select the new document and double-click it to open it in a new window”…
Oh, and it also resizes the window to roughly the middle of my screen :slight_smile:

And here’s the less insane and more readable/instructional/error-trapped version…

property activeDB : "File Types"
property removeOriginals : true

tell application id "DNtp"
	if not (exists database activeDB) then return -- Optionally, the database could be opened.
	
	set sourceGroup to (get record at "/Text/Files/Plain text/" in database activeDB)
	set recordsToMerge to (children of sourceGroup whose (type is txt))
	if recordsToMerge is not {} then
		set mergedDoc to merge records recordsToMerge
		set theTab to open tab for record mergedDoc
		set bounds of think window of theTab to {350, 0, 1100, 800}
		if removeOriginals then move record recordsToMerge to trash group of database activeDB
	end if
end tell

Weird, it works for me.

That’s not necessary. KM simply waits. If nothing more comes after the O, something is executed, if another O comes, something else.