Sample Header Ad - 728x90

Convert GUI text selections, in place, from "UPPER CASE", "lower case", or "Sentence Case" to desired case with keybindings

1 vote
0 answers
151 views
I use Arch linux and Openbox window manager and bash. Everything is up to date with the latest available versions. Often I need to change the case of selected text that is the wrong case in applications such as - libreoffice writer - google docs - gedit - geany eg I select the text "THE BRIGHT DAY" and wish to change it with some simple keystrokes/ keybinding to "the bright day". Below I have implemented very simple command line tools called by Openbox key bindings to change the case as desired. These are stored in Openbox's keybindings/ set-up file rc.xml file as follows ###################################### ########## c-fn - key chain ########## ###################################### # change selected text to lowercase bash -c ' clip_zz="$(echo $(xsel) | awk '\''{print tolower($0)}'\'')"; xdotool type --clearmodifiers -- "$clip_zz" ' # CHANGE SELECTED TEXT TO UPPERCASE bash -c ' clip_zz="$(echo $(xsel) | awk '\''{print toupper($0)}'\'')"; xdotool type --clearmodifiers -- "$clip_zz" ' # Change Selected Text To Sentence Case Like This With Each Words First Letter Being Capatalised bash -c ' clip_zz="$(echo $(xsel) | awk '\''{print tolower($0)}'\'' | sed '\''s@\([[:lower:]]\)\([[:alnum:]]*\)@\u\1\2@g'\'')"; xdotool type --clearmodifiers -- "$clip_zz" ' Although these work when going from upper to lower case it will replace "IT'S" with "itNs" because of a limitation in xdotool. I'm wondering if this can be done more neatly with "xclip" or "xsel" or some another way. It's very handy to have universal keybindings for changing the case of any selected text.
Asked by Kes (909 rep)
Jul 18, 2023, 09:22 AM
Last activity: Jul 18, 2023, 01:07 PM