Skip to content

Instantly share code, notes, and snippets.

@juanje
Created August 11, 2011 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanje/1139399 to your computer and use it in GitHub Desktop.
Save juanje/1139399 to your computer and use it in GitHub Desktop.
Get the app that should be launched for a specific hardware Type
#!/usr/bin/env python
from xdg import IniFile, BaseDirectory, DesktopEntry
from os import path
import pynotify
# Desktop Notifications Specification: http://www.galago-project.org/specs/notification/0.9/index.html
title = "HANS: Device detected"
message = "An ebook has been plugged"
timeout = pynotify.EXPIRES_DEFAULT
transient = True
if pynotify.init("HANS " + "Notifications"):
notify = pynotify.Notification(title, message)
#notify.set_icon_from_pixbuf(icon)
notify.set_category('device.added')
notify.set_urgency(pynotify.URGENCY_LOW)
notify.set_hint('transient', transient)
notify.set_timeout(timeout)
if not notify.show():
print "Failed to show the notification"
else:
print "Failed to init the notification"
mime_filename = 'applications/mimeapps.list'
launchers = []
for dirname in BaseDirectory.xdg_data_dirs:
mime_path = path.join(dirname, mime_filename)
if not path.exists(mime_path):
continue
mime_file = IniFile.IniFile(filename=mime_path)
for section in mime_file.content.values():
if section.has_key('x-usb-device/ebook'):
launcher = section['x-usb-device/ebook']
launchers.append(launcher)
for dirname in BaseDirectory.xdg_data_dirs:
for launcher in launchers:
launcher_path = path.join(dirname, 'applications', launcher)
if path.exists(launcher_path):
launchers[launchers.index(launcher)] = launcher_path
for launcher in launchers:
if path.exists(launcher):
launcher_entry = DesktopEntry.DesktopEntry(filename=launcher)
print "Exec= " + launcher_entry.getExec()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment