Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rofi modi for KDE services
#!/usr/bin/env python3
import os
import sys
import glob
import itertools
import subprocess
from configparser import ConfigParser
KS5_DIR = "/usr/share/kservices5"
def launch(entry):
# Any better way to "log" ?
with open("/tmp/a.txt", "w") as w:
# I once ran this, and everything FROZE!
# Had to go into system shell and pkill rofi
# "xmessage",
# entry
# ])
def list_entries():
def read_desktop(file):
cfg = ConfigParser(strict=False, interpolation=None)
with open(file) as fp:
# Some files are missing
cfg.read_file(itertools.chain(['[global]'], fp), source=file)
return cfg
for file in glob.glob(f"{KS5_DIR}/*.desktop"):
de = read_desktop(file)['Desktop Entry']
# For now, only focus on services
if de['type'] != 'Service' or 'Exec' not in de:
name = de['Name']
comment = ''
if 'Comment' in de:
comment = f"<span weight='light' size='small'><i>({de['Comment']})</i></span>"
icon = de.get('Icon', '')
exec = de['Exec']
# For some bizarre reason, this works correctly!
# print(f"{comment}\x00markup-rows\x1ftrue")
# But when I do this, it fails - as in, the comment loses its markup
print(f"{name} - {comment}\x00markup-rows\x1ftrue")
# Neither of these work
# print(f"<span weight='normal' size='medium'>{name}</span>\x00markup-rows\x1ftrue")
# print(f"<span weight='light' size='small'><i>({name})</i></span>\x00markup-rows\x1ftrue")
# print(f"\0message\x1fSpecial <b>bold</b> message\n")
# name = f"<span weight='light' size='small'><i>{name}</i></span>"
# message\x1f<i>({de['Comment']})</i>
# print(f"{name}\0message\x1f{comment}\0icon\x1f{icon}\0exec\x1f{exec}")
# print(f"{name} - {exec}\0icon\x1f{icon}")
# print(f"{name}\x00markup-rows\x1ftrue")
if __name__ == "__main__":
args = sys.argv
if len(args) > 1:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment