Created
August 24, 2025 20:19
-
-
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.
This file contains hidden or 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
| 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