macstories / obsidian-shortcut-launcher

Trigger shortcuts in Apple's Shortcuts app from Obsidian with custom commands.
MIT License
187 stars 10 forks source link

Feature Request: replace selected text with output of shortcut #7

Open yotamDvir opened 2 years ago

yotamDvir commented 2 years ago

I created shortcuts that take text as input and add/remove > to the beginning of each line (increase/decrease the quotation level), which I use with the selected text. It would be nice if the output of the shortcut would replace the selection.

My current workaround is to have the shortcut put the output in my clipboard and then I just paste it, but this is a bit cumbersome.

zanodor commented 1 year ago

I created shortcuts that take text as input and add/remove > to the beginning of each line (increase/decrease the quotation level), which I use with the selected text. It would be nice if the output of the shortcut would replace the selection.

My current workaround is to have the shortcut put the output in my clipboard and then I just paste it, but this is a bit cumbersome.

Shortcuts cannot paste, in or out of Obsidian, alas.

lzilioli commented 9 months ago

Shortcuts cannot paste, in or out of Obsidian, alas.

The request here is for obsidian-shortcut-launcher to receive the output of the shortcut and paste it into the current document when the shortcut returns... NOT for the shortcut itself to paste any text into the document. Currently the obsidian-shortcut-launcher seems to totally ignore whatever is returned by the shortcut, hence the clipboard workaround described by @yotamDvir

I would like to +1 the original request here, and add that I would like a few options with what to do with the output of my shortcut:

  1. replace selected text
  2. replace current paragraph
  3. replace current section
  4. replace entire note
  5. create new note (that is automatically linked back to the current note from which the shortcut was run)

For what its worth, I have worked around this shortcoming for now by using keyboard maestro instead.

zanodor commented 9 months ago

You can help yourself with a Templater Js snippet to insert clipboard content with:

<%*
clipboard = (await tp.system.clipboard());
tr += clipboard;
_%>

Look up some of these lines on the Obsidian Forum for context or clarity.

lzilioli commented 8 months ago

I just pushed a commit to my fork that addresses this request. Its been working great for me.

image image

There is one bug in the insertion logic as it initially looks like this:

image

If someone could help me clean that up, i think this might be a decent candidate to mainline.