include currently selected text in external tool command

Having trouble installing Oxygen? Got a bug to report? Post it all here.
WolfhartT
Posts: 9
Joined: Mon Aug 21, 2023 7:36 pm

include currently selected text in external tool command

Post by WolfhartT »

Hello,

I would like to use the External Tools feature to launch a web browser with the currently selected text included in the command (that is, in the URL to be opened by the web browser). How can that be done? I saw somewhere that there is a variable called ${selection}, but using this variable in the external tool command does not seem to work, the variable is not expanded when the command is executed (i.e., the URL contains the string "${selection}" rather than the selected text).

Thank you in advance for your help!
Wolfhart
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: include currently selected text in external tool command

Post by Radu »

Hi Wolfhart,
We expand the ${selection} editor variable only in code templates and in custom Author operations.
Are you editing the XML document in the Text or in the Author visual editing mode?
As the selection may contain spaces which need to be escaped maybe you could somehow add your own editor variable with a plugin, like for example this plugin implemented in Javascript which expands a ${clipboard} editor variable:
https://github.com/oxygenxml/wsaccess-j ... rVariables
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
WolfhartT
Posts: 9
Joined: Mon Aug 21, 2023 7:36 pm

Re: include currently selected text in external tool command

Post by WolfhartT »

Hi Radu,
Thank you for the reply!
I'm working in text mode.
In my particular case, the spaces do not need to be escaped: I want to translate the selected text into another language with DeepL, and with DeepL (unlike with Google Search or Google Translate, say) you don't need to escape anything, you can just dump the text as it is at the end of the URL (e.g., "https://www.deepl.com/translator#en/de/This is a test").
I have never used plugins. Where can I find information about how this works?
Best,
Wolfhart
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: include currently selected text in external tool command

Post by Radu »

Hi Wolfhart,
Before diving into how Oxygen plugins work, maybe you can try to install and use our free Translation Helper add-on which supports Google Translate and DeepL, although it works with the XML opened in the Author visual editing mode:
https://www.oxygenxml.com/doc/ug-editor ... addon.html
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
WolfhartT
Posts: 9
Joined: Mon Aug 21, 2023 7:36 pm

Re: include currently selected text in external tool command

Post by WolfhartT »

Hi Radu,
I do not use Author view, so I think that the Translation Helper add-on will not help me. Could you point me in the direction of where I can find out how to do it with a plug-in?
Thanks,
Wolfhart
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: include currently selected text in external tool command

Post by Radu »

Hi Wolfhart,
Maybe this would be a good getting started for developing Oxygen plugins:
https://www.oxygenxml.com/doc/ug-editor ... ugins.html
But let's first try to install an existing sample plugin which would get you close to what you want:
1)
So there is this Github project with lots of sample plugins:
https://github.com/oxygenxml/wsaccess-j ... ree/master
2)
In the Github user's interface there is a "Code" drop down button which allows you to download locally a zip with the entire set of project folders. Once you unzip the project locally, copy the folder "customEditorVariables" to the "OXYGEN_INSTALL_DIR/plugins" folder and re-start Oxygen.

3) Then restart Oxygen and look in the Oxygen "Preferences->Plugins" page if the plugin appears as installed.
This particular plugin expands an editor variable named "${clipboard}" to what you have previously copied. So if you use "${clipboard}" in the external tool's command line, you could first copy the selection from the Text editor using Ctrl-C, then invoke the external tool which should receive the clipboard contents as an expansion of "${clipboard}". So maybe this is close to what you want.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
WolfhartT
Posts: 9
Joined: Mon Aug 21, 2023 7:36 pm

Re: include currently selected text in external tool command

Post by WolfhartT »

Dear Radu,
Thank you for the precise instructions! The plugin implementing the $(clipboard) variable works very well.
I am wondering: Would it be difficult to modify the plugin so that it implements something like the $(selection) variable (i.e., a $(selection) variable that can be used in external tool commands)? This would be just to avoid having to hit Ctrl + C before launching the external tool.
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: include currently selected text in external tool command

Post by Radu »

Hi Wolfhart,
I committed in the project a plugin which resolves ${selection} by looking at the selected text in the current selected document:
https://github.com/oxygenxml/wsaccess-j ... orVariable
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
WolfhartT
Posts: 9
Joined: Mon Aug 21, 2023 7:36 pm

Re: include currently selected text in external tool command

Post by WolfhartT »

Hi Radu,
Works perfectly, thank you very much!
Post Reply