Created
February 15, 2022 13:43
-
-
Save ramboldio/6de07f30538ec85f8c27aaa653eca807 to your computer and use it in GitHub Desktop.
Link Opener for URL file formats
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
#!/bin/python3 | |
""" | |
opens links in link file formats on all operating systems | |
currently supported | |
Apple's .webloc & Dropbox' .web | |
© Lukas Rambold <lukas@rambold.de>, 2022 | |
MIT License | |
""" | |
import sys | |
import subprocess | |
filepath = sys.argv[1] | |
if filepath.endswith(".web"): | |
import json | |
with open(filepath, 'r') as file: | |
url = json.load(file)["url"] | |
elif filepath.endswith(".webloc"): | |
from xml.etree.ElementTree import parse | |
with open(filepath, 'r') as file: | |
url = parse(file).findall("./dict/string")[0].text | |
else: | |
raise Exception("only .web files as used in dropbox or .webloc files as used in .webloc files as used in MacOS are supported.") | |
if sys.platform=='win32': | |
os.startfile(url) | |
elif sys.platform=='darwin': | |
subprocess.Popen(['open', url]) | |
else: | |
try: | |
subprocess.Popen(['xdg-open', url]) | |
except OSError: | |
print('Please open a browser on: '+url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment