I’ve been a loyal user of Firefox for years and plan to still use it as my secondary browser (and will use it regularly for Zotero). But Google’s new browser, Chrome, has really impressed me and I’m going to start using it as my primary browser for email, surfing the web, and every day online activities. Why is it better? It’s faster, does a better job rendering flash on Linux, doesn’t require restarts to install extensions, and isolates tabs, so if one crashes it doesn’t kill all of your other tabs. In short, Chrome has become a better browser than Firefox for everyday browsing.
I had held off switching to Chrome for several months because I was hoping someone would create a Chrome extension similar to clippings for Firefox. I’m still hoping someone will, but I figured out a way to work around it on Ubuntu Linux. It’s not for the faint-of-heart or novice computer user, but it does work, and works quite well. Basically, what I’ve done is installed some software that allows me to paste text into any window, unlike clippings, which only let me paste text into Firefox.
Here’s how you do it:
Ubuntu comes with some cool keyboard shortcuts built in, and includes the ability to customize a lot of those shortcuts. But it doesn’t come with the ability to paste text as a keyboard shortcut with the default install (learned this here). In order to do that, you need to install a program called “xbindkeys.” While you’re at it, you may as well install the GUI for setting the keybindings “xbindkeys-config” and the program you’ll use to generate the text “xvkbd”. You can install them all at once from the terminal (or find them in the Synaptic Package Manager and install them there):
$ sudo apt-get install xbindkeys xbindkeys-config xvkbd
Once you’ve installed “xbindkeys,” the first thing you need to do is create a default configuration file for it from the terminal:
$ xbindkeys -d > /home/your-user-name/.xbindkeysrc
Once that’s done, go ahead and open the xbindkeys GUI by typing the following at the terminal:
This will pull up the xbindkeys GUI:
In here, you can create the key bindings to generate the text you want. This involves 6 steps.
1) At the bottom of the GUI, select “New”:
A new line in the list of keybindings will appear. Select it.
2) At the top right, choose a name for the keybinding and put it in the field labeled “Name:”
I don’t know that the name you choose here is particularly important, but you should probably make it something you’ll recognize.
3) Set the key binding. the xbindkeys GUI includes the ability to capture key combinations. All you have to do is press the “Get Key” button, wait a second for a small window to pop up, then press the desired key combination (e.g., Control+Mod2+Mod4+1). The GUI should capture everything for you correctly. The key combination will be coded into the language xbindkeys understands and will be put in the “Key:” field (e.g., Control+Mod2+Mod4+1 | m:Ox54 + c:10). What all of the code in the “Key:” field means, I’m not sure, but some of it is explained in the actual configuration file (which you created above; it’s located here: /home/your-user-name/.xbindkeysrc).
4) You then need to tell xbindkeys what to do when you press the key combination you just set up (this is called the “Action”). In order to paste text into a window, you have to actually call up a different program, which is why we installed it earlier. That program is xvkbd, an on-screen keyboard program. You won’t see the keyboard when you press the key combination, but it does generate the text for you. Here’s the command you use in the “Action:” field to generate text:
xvkbd -xsendevent -text “your text here“
The first part “xvkbd” opens the xvkbd program. The second part “-xsendevent” tells it to send an event to the X window. The third part “-text” tells it what type of event – text.
A couple of notes on the text you can include using this command are in order. First, you can put pretty much anything you want inside the quotes, except additional quotes, which the program doesn’t seem to recognize are quotes inside the quotes. So, don’t try quotes inside quotes. You can also include things like “Return” and “Tab.” I couldn’t figure out how to do that initially, which is why I ended up writing this tutorial. What I wanted to include in the text I was pasting was the text I usually include in my email signature:
I was able to include the text, but couldn’t figure out how to include the line break. So, what I was initially getting when I pressed my key combination was:
I initially thought, erroneously, that the command for “Return” would be included in xbindkeys list of commands. Nope. The command for “Return” is part of xvkbd. I eventually found it on that software’s website: \r. So, if you want to create something like an email signature with a line break, here’s how it would look:
xvkbd -xsendevent -text “Best,\r\rRyan”
Note I’ve included two Return commands (i.e., “\r\r”) as one will just return me to the next line. I needed 2 for a blank line between “Best,” and “Ryan.”
5) You’re not quite done at this point. I found the GUI for xbindkeys to be a bit buggy. Before you do anything else, you should hit the buttons “Apply” and “Save & Apply & Exit”:
This will close the program, but it will also make sure that everything you just typed in will be saved in the configuration file. I have 5 different keyboard bindings for text I use regularly, 3 email signatures and 2 other text snippets. I created the first email signature, then started on the second and the GUI crashed, losing all my work. So, just hit the “Apply” and “Save & Apply & Exit” button after every keyboard binding you create just to be safe.
6) Test it. Open up a file or browser and try your keyboard combinations. If the text is pasted in – voila, you’re done. If not, well, you did something wrong or, well, who knows. The nice thing about this approach is that it is browser agnostic – it will paste your text into any browser or any other text input box for that matter.
There are a couple of additional things you should do with xbindkeys before you’re done. First, a nifty keybinding that is included in the default configuration file is “CONTROL+SHIFT+q”, which opens up a list of all of your current keybindings:
This isn’t all that important to know, but it is a nice little feature.
You should also know that you can edit your configuration file by hand, though doing so is a bit tricky as the code for the key combinations isn’t all that intuitive. To do so, use the following command at the terminal:
$ gedit /home/your-user-name/.xbindkeysrc
Finally, once you’ve gotten everything working, if you want to make sure xbindkeys starts when you boot your computer, add it to the Startup Applications: “System -> Preferences -> Startup Applications”
2,097 total views, 1 views today
5 thoughts on “Ubuntu: xbindkeys to replace Firefox’s clippings extension”
very nice, just what I was looking for, very detailed. I also had the same problem about moving to Chrome…. Thanks a lot!!
any clues on how to make it work with characters from other languages? for example, words like: “atrás”, “mañana”, “pingüino”, “você tinha o almoço”…. it’s giving me a hard time…
I haven’t run into that problem, but I’m guessing xvkbd can handle characters from other languages. I looked on the main information page for xvkbd (see here: . It does support alternate keyboards. If you type “xvkbd” into a terminal, it will pop up the virtual keyboard that is used to enter the text. In the bottom left corner there is an “xvkbd” button. If you select it, you’ll see an option to “change keyboard layout”. You can select “Spanish.” That may help.
Alternatively, there is now something similar to clippings for Chrome, though it doesn’t have keyboard shortcuts. It’s called “Papercuts”:
I use it for some of the more complicated things I paste regularly.
I hope this helps.
Hi again Ryan.
I looked up your advice and yes, switching the keyboard layout allowed me to write the special characters I needed. In that case, the new layout Latin1 did a great job. But since there is no option to start the keyboard with the Latin1 layout, and xvkbd does not remember the layout selected once you close it, I couldn’t use those special characters for the -text option
Since I looked up all over the web for about 2 days for a way to write latin characters with xvkbd -text command, and found nothing, I feel I need to share my solution: While looking into the file /etc/X11/app-defaults/XVkbd-common I found the labels for all the keys in the keyboard, and with that label, I was able to simulate a key stroke of any of the “dead keys” of the default keyboard, using the keysym operator ( [key_label] ), so I came up with this:
In order to write this spanish sentence:
Mañana intentaré ir tras ese pingüino
The line you should include in the xbindkeys is:
xvkbd -xsendevent -text ‘D3MaD1[dead_tilde]nana intentarD1[dead_acute]e ir tras ese pingD1[dead_diaeresis]uino’
I also included D3 and D1, which are “delays”, at the beginning (300ms) and before every dead key stroke (100ms), because without them, the special characters (ñ, é, ü) appear at the beginning of the sentence. This might be a local performance issue, but oh well….
I have no clue how to make this work with other special characters, like portugese, greek or german, I leave that for others to look for.
Thanks again for your help Ryan, I appreciate
I’m glad you found a solution. I figured it must be possible, but I had not run into that issue. Your solution will be available to everyone. Thanks for posting it!