2

我在 Ubuntu 12.04 上的 WINE 中运行 Foxit Reader。我想将文本复制并粘贴到书签中,但我需要将其大写(例如,fusion 变为 Fusion)。我想按 F5 并运行 python 脚本。我知道 Autokey 可以做到这一点,但后者的剪贴板处理有一个记录在案的错误。

所以,现在我正在寻找 Autokey 的剪贴板替代品。如果我的 python 脚本运行一个 shell,也许 shell 可以访问剪贴板?xclip 似乎很有希望,但它的文档说,“从标准文件中读取,或者从一个或多个文件中读取,并将数据作为 X 选择提供,以便粘贴到 X 应用程序中。” 我不需要标准或文件;我需要正确的 X11 剪贴板(又名选择)。

简而言之,python 或 shell 如何读取现有的 X11 剪贴板?

4

2 回答 2

2
xclip -o | sed 's/^./\U&/g' | xclip -i

这将读取 X 剪贴板,将内容大写并覆盖它

于 2013-04-04T22:05:41.903 回答
1

我意识到-o参数读取一个选择,但您必须指定您需要的:

xclip -selection clipboard -o

从那里,我使用了这个StackOverflow 答案。它工作得很好。

#read clipboard, avoid autokey's get_selection bug
tag = subprocess.Popen(["xclip","-selection", "clipboard", "-o"],stdout=subprocess.PIPE).communicate()[0]

#https://stackoverflow.com/questions/764360/a-list-of-string-replacements-in-python
mapping = { "'":'', ',':'', '"':'', ';':'', '(':'', ')':'', '.':'', '-':' '}
for k, v in mapping.iteritems():
    tag = tag.replace(k, v)

#Camelcase, remove spaces, and append Caesar tag
tag=tag.title().replace(' ','')+"_"
于 2013-04-04T21:53:10.710 回答