函数 clipboard.get_selection() 无法获取所有选中的字符串

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

我设置了一个快捷方式以便select一段文字并打开一个URL结尾有selection。

所以这是 linux 下的 AutoKey 脚本:

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

问题是 %s 只插入了第一个单词。

所以如果我 select “我的文字是这样的” che URL 打开是:www.MY_URL.com/我的

您可能必须对文本进行编码才能在 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)