Last active
August 7, 2018 15:32
-
-
Save rcj4747/2c4200117d219d87993d6fa08f661d3d to your computer and use it in GitHub Desktop.
Watch the clipboard for URLs and open them in the browser (on Linux)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Watch the clipboard for URLs and open them in the browser (on Linux) | |
""" | |
import subprocess | |
import time | |
import pyperclip # Requires xclip to be apt installed | |
PRIOR = '' | |
while True: | |
# xsel/xclip functions support the 'primary' argument | |
PASTE = pyperclip.determine_clipboard()[1] | |
# Toggle the commented lines below to use primary/secondary clipboards | |
CURRENT = PASTE(primary=True).strip().split()[0] | |
# CURRENT = PASTE(primary=False).strip() | |
if not PRIOR: | |
PRIOR = CURRENT | |
if PRIOR != CURRENT: | |
print(CURRENT) | |
PRIOR = CURRENT | |
if CURRENT.startswith('http'): | |
subprocess.call(["xdg-open", CURRENT], | |
stdout=subprocess.DEVNULL, | |
stderr=subprocess.DEVNULL) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment