Skip to content

Instantly share code, notes, and snippets.

@BogTheMudWing
BogTheMudWing / Open Selected.py
Created August 24, 2025 20:19
I have this AutoKey script bound to Meta+S to take the current/last selected text and open it. If it's a URL (starting with https://, rtp://, m3u://, etc.), it will be opened with xdg-open. Otherwise, it will plug the query into Google as a search.
import re
import subprocess
import os
text = os.popen('xsel').read() # grab selected text
url_pattern = re.compile(r'^[a-zA-Z][a-zA-Z0-9+.-]*://\S+')
if url_pattern.match(text):
subprocess.run(['xdg-open', text])
else: