【问题标题】:Python get selected textPython获取选定的文本
【发布时间】:2018-04-29 21:08:31
【问题描述】:

我将如何使用 Python “捕捉”用户在例如网络浏览器中选择的文本?该脚本将在后台空闲,当按下某个组合键时,它会“获取”用户选择的文本。想想复制和粘贴,只有它复制到我的应用程序而不是剪贴板。

谢谢!我想指出,这将适用于 Mac。

【问题讨论】:

标签: python macos selection clipboard


【解决方案1】:
  1. 安装xsel

    sudo apt-get install xclip xsel -y
    
  2. 另存为get-selected.py

    import os
    print(os.popen('xsel').read())
    
  3. 选择文本

  4. 运行

    python get-selected.py
    

【讨论】:

猜你喜欢
  • 2012-12-10
  • 2019-09-29
  • 2016-06-22
  • 2020-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多