Instantly share code, notes, and snippets.

Embed
What would you like to do?
Open given file with the default application. Works on Linux, OS X and Windows. On Linux requires xdg-open (usually built-in).
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