Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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:
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_hint('transient', transient)
if not
print "Failed to show the notification"
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):
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']
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