开发者

Python get selected text

开发者 https://www.devze.com 2023-03-28 06:49 出处:网络
How would I, using Python \"catch\" text that a user has selecting in, for example, a web browser? The script would idle 开发者_高级运维in the background, and when a certain key combination is pressed

How would I, using Python "catch" text that a user has selecting in, for example, a web browser? The script would idle 开发者_高级运维in the background, and when a certain key combination is pressed, it "gets" the text the user has selected. Think copy & paste, only it copies to my application instead of a clipboard.

Thanks! I'd like to point out that this will be for Mac.


  1. Install xsel

    sudo apt-get install xclip xsel -y
    
  2. Save this as get-selected.py

    import os
    print(os.popen('xsel').read())
    
  3. Select text

  4. Run

    python get-selected.py
    
0

精彩评论

暂无评论...
验证码 换一张
取 消