Skip to content

Instantly share code, notes, and snippets.

@andreldm
Last active March 25, 2020 23:48
Show Gist options
  • Save andreldm/bb0bf2a2ff2dbcad05d27cd77ea715cf to your computer and use it in GitHub Desktop.
Save andreldm/bb0bf2a2ff2dbcad05d27cd77ea715cf to your computer and use it in GitHub Desktop.
A simple daemon implementing freedesktop.org's file manager interface.

Forked from: https://gist.github.com/PotatoesMaster/8038613

Use D-Feet to test or commands such as:

dbus-send --print-reply=literal --dest=org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:'/path/to/some/file.txt' string:''
#!/usr/bin/env python
# This program is free software. It comes without any warranty, to the extent
# permitted by applicable law. You can redistribute it and/or modify it under
# the terms of the Do What The Fuck You Want To Public License, Version 2, as
# published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
"""
This is a simple daemon implementing freedesktop.org's file manager interface
(http://www.freedesktop.org/wiki/Specifications/file-manager-interface/).
"""
import gi
from gi.repository import GObject
import dbus
import dbus.service
import dbus.mainloop.glib
import os
from subprocess import Popen
def open_file_manager(uri):
args = ['xdg-open']
path = str(uri)
if path.startswith('file://'):
path = path[7:]
args.append(path)
if os.fork() == 0:
Popen(args)
os._exit(0)
else:
os.wait()
class FmObject(dbus.service.Object):
@dbus.service.method("org.freedesktop.FileManager1",
in_signature='ass', out_signature='')
def ShowFolders(self, uris, startupId):
open_file_manager(uris[0])
@dbus.service.method("org.freedesktop.FileManager1",
in_signature='ass', out_signature='')
def ShowItems(self, uris, startupId):
open_file_manager(uris[0])
@dbus.service.method("org.freedesktop.FileManager1",
in_signature='ass', out_signature='')
def ShowItemProperties(self, uris, startupId):
open_file_manager(uris[0])
@dbus.service.method("org.freedesktop.FileManager1",
in_signature='', out_signature='')
def Exit(self):
mainloop.quit()
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.freedesktop.FileManager1", session_bus)
object = FmObject(session_bus, '/org/freedesktop/FileManager1')
mainloop = GObject.MainLoop()
mainloop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment