There are many applications which cannot identify and open URLs in the browser when clicked. This can be achieved using XSel (X Selection) – a small utility that can manipulate the X selection. XSel can handle three selections:
- Primary: middle mouse click (default)
- Clipboard: Text selection from a clipboard manager
XSel can be used to manipulate mouse-highlighted text selections in several ways. In this article we will use it to open links in the default browser by passing the selected text to xdg-open command. However, there is a catch, the URL must start with http://, https://, ftp:// etc. otherwise xdg-open will try to open a file of the same name from your home directory.
- Install XSel.
$ sudo apt-get install xsel
- Edit a new file /usr/local/browseURL (as sudoer) )and add the following text into it:
#!/bin/bash xdg-open $(xsel -p)
- Make the script executable for all users.
$ sudo chmod a+x /usr/bin/browseURL
- Add a hotkey to run the script.
Navigate to Keyboard settings ▸ Shortcuts ▸ +. Added the description and the command as browseURL and assign a keybind of your choice.
That’s it! Next time you highlight a URL, use the hotkey to open it directly in the browser.