pythonkeyboard-shortcutskey-bindingsarchlinuxautokey

The function clipboard.get_selection() fails to get all the selected string


I set a shortcut in order to select a piece of text and open an URL with the selection at the end.

So this is the script for AutoKey under linux:

text = clipboard.get_selection()
system.exec_command("kde-open http://www.MY_URL.com/%s" % text)

the problem is that the %s only insert the first word.

So if I select "my text is this" che URL opened is: www.MY_URL.com/my


Solution

  • You probably have to encode the text to use it in a URL:

    from urllib.parse import quote # in python2 that would be: from urllib import quote
    
    text = quote(clipboard.get_selection())
    system.exec_command("kde-open http://www.MY_URL.com/%s" % text)