Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work on kde plasma 5.23 #1

Open
jonas-frey opened this issue Nov 21, 2021 · 3 comments
Open

Doesn't work on kde plasma 5.23 #1

jonas-frey opened this issue Nov 21, 2021 · 3 comments

Comments

@jonas-frey
Copy link

I get the error message on the attached screenshot.

Screenshot_20211120_195257

@paullryan
Copy link

@jonas-frey the following version works

# -*- coding: utf-8 -*-

"""Matching KDE Services"""

import os
from functools import reduce
from albert import *

__title__ = "KDE Services"
__version__ = "0.2.1"
__authors__ = "Arto Manuel"

KDE_SERVICES_PATH = "/usr/share/kservices5/"

def get_services_path(query: str) -> list:
	services = []
	files = [file for file in os.listdir(KDE_SERVICES_PATH) if ".desktop" in file]
	for file_path in files:
		with open(KDE_SERVICES_PATH + file_path, 'r', encoding="utf-8") as f:
			for line in f.readlines():
				if "X-KDE-Keywords=" in line:
					if reduce(lambda prev, query: prev and (query in line.removeprefix("X-KDE-Keywords=").lower()), query.lower().split(' '), True):
						services.append(file_path)
	return services

def get_service_data(service_path: str) -> dict:
	data = {"Icon": "", "Name": "", "Comment": ""}
	with open(KDE_SERVICES_PATH + service_path, "r", encoding="utf-8") as file:
		for line in file.readlines():
			for key in data.keys():
				if key+"=" in line:
					data[key] = line.replace(key+"=", "").strip()
	return data

def handleQuery(query):
	if query.string:
		items = []
		services = get_services_path(query.string)
		for service_path in services:
			service_data = get_service_data(service_path)
			full_path = KDE_SERVICES_PATH + service_path
			items.append(Item(
				id=service_data["Name"],
				icon=iconLookup(service_data["Icon"]),
				text=service_data["Name"],
				subtext=service_data["Comment"],
				actions=[
					ProcAction(text = f"kcmshell5 {full_path}", commandline=["kcmshell5", full_path])
				]
			))
		return items


if __name__ == "__main__":
	services  = get_services_path("kwin")
	for service_path in services:
		service_data = get_service_data(service_path)
		print()
		print(service_path, ":", service_data)

The change that fixes it is the addition of full_path in handleQuery otherwise it uses whatever path your terminal was in last.

@Base-115
Copy link

Sadly, this appear don't work in Albert 0.21.1, even using the paullryan's alternative script.

I will need keeping use KRunner to do this search type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@paullryan @jonas-frey @Base-115 and others