Created
August 20, 2015 21:12
-
-
Save pirafrank/159aa709cc86799b66f2 to your computer and use it in GitHub Desktop.
Open given file with the default application. Works on Linux, OS X and Windows. On Linux requires xdg-open (usually built-in).
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
import sys | |
import subprocess | |
import os | |
import platform | |
def open_with_default(path): | |
current_platform = platform.system() | |
if current_platform == "Linux": | |
subprocess.call(["xdg-open", path]) | |
elif current_platform == "Windows": | |
os.system("start "+path) | |
elif current_platform == "Darwin": | |
subprocess.call(["open", path]) | |
if __name__ == '__main__': | |
open_with_default(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment