GNOME Shell 3.26.2 | Ubuntu 17.10 | Bash 4.4.12

How can I add options to the right-click drop down menu in GNOME GUI? I want to place an item in the mouse right-click menu that will do echo "$variable" >> ~/notes/notepad.txt where $variable is the currently highlighted text. Is there a way to apply this to the right-click menu globally, like copy/paste? I want to have this option basically anywhere a cut/copy option for text is available.


As far as I know the dropdown menus are program-specific, so to add a system-wide dropdown menu item you would need to adjust nearly every single program's menu accordingly, and there may very well be programs where the menu is hard-coded and not easily modifiable.

I suggest you define a global keyboard shortcut instead, there are several question on this topic here, e.g. GNOME 3 Shell keyboard/mouse shortcuts for GNOME Shell. To capture the currently selected text I recommend xclip, the command is:

xclip -o >>~/notes/notepad.txt

Note that this does not append the content of the clipboard buffer (which is filled e.g. with Ctrl+C) to the file, but the content of the primary buffer instead, which always contains the text you mark(ed). More about this important difference can be found on Unix.SE: What's the difference between Primary Selection and Clipboard Buffer?, wiki.archlinux.org and in this excellent article.
If you want to append the content of the clipboard buffer, use:

xclip -se c -o >>~/notes/notepad.txt


  • -se c – short for -selection clipboard, uses the clipboard buffer instead of the (default) primary one
  • -o – output from the selected buffer instead of writing to it (default)
  • >>~/notes/notepad.txt – redirect the output to the file ~/notes/notepad.txt appending to its content

See man xclip for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.