Skip to content

Instantly share code, notes, and snippets.

@BogTheMudWing
Created August 24, 2025 20:19
Show Gist options
  • Select an option

  • Save BogTheMudWing/f2402b99b62935c1ebdddca39eee4813 to your computer and use it in GitHub Desktop.

Select an option

Save BogTheMudWing/f2402b99b62935c1ebdddca39eee4813 to your computer and use it in GitHub Desktop.
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:
# replace spaces with + for URL encoding
query = text.replace(' ', '+')
subprocess.run(['xdg-open', f'https://google.com/search?q={query}'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment