Skip to content

Instantly share code, notes, and snippets.

@larsemil
Last active September 29, 2017 12:01
Show Gist options
  • Save larsemil/2f20262c6d8e52272647df39a7ee09f8 to your computer and use it in GitHub Desktop.
Save larsemil/2f20262c6d8e52272647df39a7ee09f8 to your computer and use it in GitHub Desktop.
pip install dmenu
#!/usr/bin/python
from dmenu import dmenu
import sys
import os
browser = 'xdg-open %s'
choices = {
'Open in thunar' : 'thunar %s',
'Open in firefox':'firefox %s',
}
if len(sys.argv) <2:
print("Call this with file url as argument.")
sys.exit()
if sys.argv[1][0:7] == 'file://':
# The url passed in to url-handler is a file:// url.
cmd = dmenu.show(choices.keys(), prompt='Choose application')
full_command = choices[cmd] % sys.argv[1]
else:
full_command = browser % sys.argv[1]
print(os.system(full_command))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment