Run JavaScript on selected text

I have a clunky workflow and would like to streamline it as much as possible.
I have tiddlers that contain compound words and phrases in Sanskrit (unicode).

Using a javascript I cobbled together, my current workflow is: Select a text phrase in a tiddler. Use MacOS context menu/Shortcut with AppleScript to open a html page with selected text as argument. On the webpage, chunk the compound phrase manually and copy the results to clipboard. Back in tiddlywiki, in the same tiddler, I paste the clipboard contents into a textarea and parse the text into their respective fields.

I’m not well versed in Tiddlywiki Script. So I came up with this javascript/html workaround. Since the process starts in a tiddler and ends in the same tiddler, what can I do to make it a smooth process?

Any thoughts?

P.S. html/javascript file attached. can only upload if it is .json
anvaya.html.json (11.1 KB)

If you documented the requirements in the action “chunk the compound phrase” I am confident this could all be done within tiddlywiki, with TiddlyWiki script and no JavaScript.

How Obsidian and Notion achieve this:

  1. Obsidian use command palette, some action can use selected text as input
  2. Notion use floating toolbar or context menu, to run AI with selected text

TW’s command palette can use selected text as input, but no one has tried this before, maybe you can have a try.

I’m also seeking a context menu plugin to build-in into TidGi app, that can execute action widget with selected text as input variable, if someone know a good one, please recommend to me.

This is how the EditorToolbar buttons work, then make use of the WidgetMessage: tm-edit-text-operation

Thank you all for the suggestions.

I don’t want to take on a whole new project rewriting it in TW script.
For now, I’m putting it in an iframe - at least saves me from going to another browser window. (for now the iframe content source is an external file; working on how to have html in a tiddler and use it to call iframe)

Next problem is how do I send a selection of text to the iframe? I’ve read about the tm-edit-text-operations but can’t quite figure out how to make the connection.

p.s. I came across the context-menu-plugin but don’t know how to adapt it to my situation. thread. plugin.

@fastfreddy might be able to help you if you want to use that context menu addon which he created.
Also can you explain your usecase with an example to understand it better

@KPtko the tiddlyclip plugin can provide this type of context menu - I have put a working example here:
https://tccontextmenu.tiddlyhost.com/

Keep in mind you have not specified what is involved with;

OR

If you did we would actually know what transformation(s) you are performing.

Having being a support professional much of my life I see this all the time (and sometimes guilty of it myself), of the user asking to solve one problem, but not describing the root cause or original requirements.

  • If I had the right skills and time I may be able to reverse engineer your example, but that demands my time and involves guesswork.
  • If I had the right requirements, I may even be able to point you to an existing solution or code one quickly.
  • I may never answer the question you asked, but give you the solution :nerd_face:

@buggyj Thanks. I was able to use tiddlyclip plugin.

@arunnbabu81 @TW_Tones I appreciate your suggestions. I couldn’t have gotten this far in my project without the help and collective knowledge in this group.

For anyone that stumbles upon this topic with a similar need:
I had a working javascript/html page that needed selected text as an argument. Using javascript UI the text is modified and numbered per my specific need. The resulting text is then copied to the clipboard. Back in TW, i’m using TWscript to put specific numbered items into fields.
My need was to streamline this process. Rewriting in TWscript was a last option. Now, I use tiddlyclip to select text, right-click and pass it as argument to an iframe that references my javascript/html page. Copy-paste the result back into tiddler field. All done in TW.

I’m sure there is room for improvement, but for now this works.