Open selected URL from your desktop in the browser

cool_penguin_smallThere 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)
  • Secondary: <Ctrl-c>, <Ctrl-v>
  • 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.

Steps:

  1. Install XSel.
    $ sudo apt-get install xsel
  2. Edit a new file /usr/local/browseURL (as sudoer) )and add the following text into it:
    #!/bin/bash
    xdg-open $(xsel -p)
  3. Make the script executable for all users.
    $ sudo chmod a+x /usr/bin/browseURL
  4. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *