Skip to content

Instantly share code, notes, and snippets.

@spencerwi
Last active January 30, 2025 04:59
Show Gist options
  • Save spencerwi/9df345652a1f312167e3461274658cbe to your computer and use it in GitHub Desktop.
Save spencerwi/9df345652a1f312167e3461274658cbe to your computer and use it in GitHub Desktop.
KDE Windows Albert extension using kdotool
import subprocess
from albert import *
md_iid = '2.4'
md_version = '1.0'
md_name = 'KDE Windows'
md_description = 'Allows you to search windows in KDE (both X11 and Wayland) using kdotool'
class Plugin(PluginInstance, TriggerQueryHandler):
def __init__(self):
PluginInstance.__init__(self)
TriggerQueryHandler.__init__(self, self.id, self.name, self.description, defaultTrigger = 'w ')
def handleTriggerQuery(self, query):
items = []
query_string = query.string
list_window_ids_proc = subprocess.run(['kdotool', 'search', query_string], stdout=subprocess.PIPE)
window_ids = [w.strip() for w in list_window_ids_proc.stdout.decode('utf-8').strip().split('\n') if w.strip()]
for window_id in window_ids:
get_window_name_proc = subprocess.run(['kdotool', 'getwindowname', window_id], stdout=subprocess.PIPE)
window_name = get_window_name_proc.stdout.decode('utf-8').strip()
get_class_name_proc = subprocess.run(['kdotool', 'getwindowclassname', window_id], stdout=subprocess.PIPE)
window_class_name = get_class_name_proc.stdout.decode('utf-8').strip()
if window_name:
items.append(
StandardItem(
id=window_id,
text=window_name + " – " + window_class_name,
iconUrls=['xdg:' + window_class_name],
actions=[
Action(
'activate',
'Activate',
lambda wid=window_id: runDetachedProcess(['kdotool', 'windowactivate', wid])
)
]
)
)
query.add(items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment