user825286
user825286

Reputation:

Python get selected text

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.

Upvotes: 5

Views: 7803

Answers (1)

user3408094
user3408094

Reputation: 31

  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
    

Upvotes: 3

Related Questions