Skip to content

Instantly share code, notes, and snippets.

Last active Jul 24, 2019
What would you like to do?
Derived from, with small changes (such as porting to Python 3 and respecting TERMCMD, if set). Useful for things like making Deluge open ranger when you click "Open Download Folder".
#!/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 for more details.
This is a simple daemon implementing's file manager interface
from gi.repository import GLib
import dbus
import dbus.service
import dbus.mainloop.glib
import os
from subprocess import Popen
def open_file_manager(uri, select=False):
termcmd = os.environ.get('TERMCMD') or 'kitty'
args = [termcmd, '-e', 'ranger']
if select:
path = str(uri)
if path.startswith('file://'):
path = path[7:]
if os.fork() == 0:
class FmObject(dbus.service.Object):
in_signature='ass', out_signature='')
def ShowFolders(self, uris, startupId):
in_signature='ass', out_signature='')
def ShowItems(self, uris, startupId):
open_file_manager(uris[0], select=True)
in_signature='ass', out_signature='')
def ShowItemProperties(self, uris, startupId):
open_file_manager(uris[0], select=True)
in_signature='', out_signature='')
def Exit(self):
if __name__ == '__main__':
session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.freedesktop.FileManager1", session_bus)
object = FmObject(session_bus, '/org/freedesktop/FileManager1')
mainloop = GLib.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment