Site Map - skip to main content - dyslexic font - mobile - text - print

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


From Wed 20th December 2017 all the media from the HPR feeds will be served via a redirect towards Archive.org. Please notify admin@HPR of any issues.

Our hosting is kindly provided by Josh from AnHonestHost.com. We would appreciate it if you could donate to help reduce his costs in funding the hosting.
He is also accepting bitcoins to 1KsxJr9HtsdaUeU7yaV9bk9bQi21UPBtUq

hpr1750 :: xclip, xdotool, xvkbd: 3 CLI Linux tools for RSI sufferers

3 command-line tools that save me hundreds of keystrokes a day.

<< First, < Previous, Latest >>

Host Image
Hosted by Jon Kulp on 2015-04-17 is flagged as Clean and is released under a CC-BY-SA license.
Listen in ogg, spx, or mp3 format. | Comments (9)

Part of the series: Accessibility

Shows about tearing down the barriers for our fellow hackers.

Basic commands

Type the words "foo bar" with xvkbd:

xvkbd -xsendevent -secure -text 'foo bar'

Types out the entire contents of the file "foobar.txt" with xvkbd:

xvkbd -xsendevent -secure -file "foobar.txt"

Send text to the clipboard:

xclip -i

Send clipboard contents to standard output:

xclip -o

Do virtual Ctrl+C key combination with xdotool:

xdotool key Control+c

Save this complicated command as an environment variable—then the variable "$KEYPRESS" expands to this command.

export KEYPRESS="xvkbd -xsendevent -secure -text"

Examples

With virtual keystrokes and CLI access to the clipboard, you're limited only by your imagination and scripting ability. Here are some examples of how I use them, both for the manipulation of text and for navigation. The words in bold-face are the voice commands I use to launch the written commands.

Capitalize this. Copies selected text to the clipboard, pipes it through sed and back into the clipboard, then types fixed text back into my document:

xdotool key Control+c && xclip -o \
| sed 's/\(.*\)/\L\1/' \
| sed -r 's/\<./\U&/g' \
| xclip -i && $KEYPRESS "$(xclip -o)"

Go to grades. This example takes advantage of Firefox "quick search." I start with a single quote to match the linked text "grades" and press the Return key (\r) to follow the link:

$KEYPRESS "'grades\r"

First Inbox. From any location within Thunderbird I can run this command and it executes the keystrokes to take me to the first inbox and put focus on the first message:

xdotool key Control+k && $KEYPRESS "\[Tab]\[Home]\[Left]\[Right]\[Down]" && sleep .2 && xdotool key Tab

single ex staff. Type out an entire Lilypond template into an empty text editor window:

xvkbd -xsendevent -secure -file "/path/to/single_ex_staff.ly"

Paragraph Tags. Puts HTML paragraph tags around selected text:

#!/bin/bash

KEYPRESS='xvkbd -xsendevent -secure -text'

xdotool key Control+c

$KEYPRESS '<p>'
xdotool key Control+v
$KEYPRESS '</p>'

Launching commands with keystrokes in Openbox

I normally use blather voice commands to launch the scripts and keystroke commands, but I have a handful of frequently-used commands that I launch using keystroke combos configured in the Openbox config file (~/.config/openbox/rc.xml on my system). This block configures the super+n key combo to launch my examplelink.sh script.

<keybind key="W-n">
  <action name="Execute">
	<startupnotify>
	  <enabled>true</enabled>
	  <name>special</name>
	</startupnotify>
	<command>examplelink.sh</command>
  </action>
</keybind>

Links


Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2015-04-17T19:45:26Z by Jon Kulp

Correction/Improvement

I find now that I can streamline the "capitalize this" command by cutting out the last couple of xclip things, like this:

xdotool key Control+c && $KEYPRESS "$(xclip -o | sed 's/\(.*\)/\L\1/' | sed -r 's/\&lt;./\U&/g')"

Comment #2 posted on 2015-04-21T10:41:50Z by Dave Morriss

Fascinating stuff

Hi Jon,

This was very interesting. I'm impressed at how much you can do with such tools and Blather.

I wondered, is there any particular reason why you don't define KEYPRESS as an alias. I think that's what I would have done. I'd have added it to ~/.bash_aliases which I source in my ~/.bashrc.

I'm not sure that it adds a great deal since aliases are just shortcuts and don't offer much else in the way of features. Just wondering.

The sed tricks link makes good reading by the way.

Dave

Comment #3 posted on 2015-04-21T15:26:30Z by Mike Ray

Terrific podcast

This was a great podcast. 19 minutes of inspiration. John's podcasts are always worth a listen but this was particularly good. I will definitely be having a go at some of this and investigating how I can make life easier with these tools

Comment #4 posted on 2015-04-22T00:59:18Z by Jon Kulp

Thanks Mike; Response to Dave

Thanks, Mike! So glad to hear you enjoyed podcast.

Dave, I don't really know why I didn't try using a bash alias for this. I have a bash alias file with something like 200 lines in it so I definitely know how to do it. Somehow it seemed like creating an environment variable in my blather launch script was the right way to go, and since that worked I never tried doing a different way.

Comment #5 posted on 2015-04-22T11:54:47Z by Jon Kulp

Mike: ping me for help

Mike, If you're going to try to get blather up and running, let me know if I can help in any way. The script I wrote for Debian normally will get you to the "hello world" stage in one command, but it's possible that something could go wrong. If there's anything I can do to help you get started, let me know.

Comment #6 posted on 2015-04-23T08:45:47Z by Mike Ray

Blather and xvkbd as shortcuts in Debian

Will do John. I've just installed Debian Jessie RC3 on a laptop and I'm setting up some keyboard shortcuts so I will possibly try to get Blather up and running with the x tools to do the same job

Comment #7 posted on 2015-09-27T12:29:01Z by Rob Blaine

Blather works great!

Hi Jon

Just a word of thanks for all your scripts and debian installation script for Blather. I'm a musician making use of Blather to reduce the number of hours spent using my hands on a keyboard and trackball. I also have a repetitive injury called hand dystonia, so I can definitely empathise with RSI sufferers. Your scripts are great help! - Best regards Rob.

Comment #8 posted on 2015-09-27T22:40:51Z by Jon Kulp

Blather

Hi Rob, thanks for the message, it's so great to hear about someone else using Blather to make life easier, although I'm very sorry to hear about your injury. If it's any consolation, one of my colleagues here at the University suffered from focal dystonia and seems to have made a complete recovery and is performing again all the time on the violin.

Comment #9 posted on 2015-09-28T19:35:10Z by Rob Blaine

Blather and RSI

Hi Jon, seems as though not enough people recognize the potential for programs like Blather. Thanks for the encouragement - I discovered some years ago via the net that retraining was the key to recovery (despite neurologists claiming I'd never perform again) ........a very slow process, but definitely worth my while. I hope your surgery / injury improves with time, though I can imagine an amount of wrist pain is inevitable. Keep up the good work with Blather.......Thanks again!

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to
record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the P in HPR stand for ?
Are you a spammer →
Who hosted this show →
What does HPR mean to you ?