Skip to content

Instantly share code, notes, and snippets.

@pirafrank
Created August 20, 2015 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pirafrank/159aa709cc86799b66f2 to your computer and use it in GitHub Desktop.
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).
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