As someone who’s trying to learn a foreign language, having a dictionary by my side is quite trivial.

One thing I do enjoy when using the gnome desktop is its dictionary and the fact that I can actually edit all the keyboard shortcuts the way I want to open up different windows and perform different tasks.

One idea that came to my mind recently was to actually use this feature, to improve my learning process. Ideally I’d wanted to select a text in a window (e.g A word I see in my browser or a PDF file) and then, without doing copy-paste, open the dictionary and look for the meaning of that word.

Seemed that it’s quite easy to do so on gnome-desktop. Therefore, I thought of writing this small article and share it with anyone who also wants to do the same, or get some ideas and improve it.

To do so, we need to first install a command-line tool called xsel. As it’s stated in its repo:

XSel is a command-line program for getting and setting the contents of the
X selection. Normally this is only accessible by manually highlighting
information and pasting it with the middle mouse button.

Source: https://github.com/kfish/xsel

Assuming you’re using the Ubuntu operating system, open up a terminal and install this tool using:

$ sudo apt install xsel

Then open the Settings app and select “Keyboard Shortcuts”:

Selected the “Keyboard Shortcuts” in the Settings

Scroll down and click on the “+” icon to add a new shortcut:

You can give a new to your shortcut here, I gave it “Open dictionary”. Then for its command, give the following:

sh -c 'gnome-dictionary "$(xsel)"'

Then give the desired shortcut, which upon pressed will run the command.

It basically runs a shell command, opens the gnome-dictionary app and passes the currently selected text (with the help of xsel) to it. This will eventually open the app, and you’ll have the text already set in the main input of the app.

That’s it, write to me in the comments, how would you improve the process here?

Take care and stay safe

Using gnome dictionary like a professional