Home > Linux > KNotify-Popups per Shell/Python

KNotify-Popups per Shell/Python

Manchmal will man einem Script oder Programm die Möglichkeit geben, sich dem Benutzer dezent mitzuteilen, obwohl es minimiert oder irgendwo im Hintergrund läuft. KDE hat für solche Zwecke KNotify (eine Notification Area im Systray) vorgesehen. KNotify anzusteuern ist seit D-Bus-Zeiten nicht mehr ganz so einfach wie früher. Mit einem kleinen Skript gehts aber doch flott und komfortabel.

Hier ist der Quellcode dafür: (knotify.py)

#!/usr/bin/python
import sys, dbus
knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify")
try:    title, text = sys.argv[1:3]
except: print 'Usage: knotify.py <title> <text>'; sys.exit(1)
knotify.event("warning", "kde", [], title, text, [], [], 0, \
              dbus_interface="org.kde.KNotify")

So schauts aus, wenn das Skript aufgerufen wird:
KNotify Skript Beispiel

Ein direkter Aufruf per qdbus scheint übrigens nicht möglich zu sein, da die aufzurufende Methode eine QVariantList als Argument erwartet und die Bash keine Konvertierung zu diesem Datentyp zu unterstützen scheint. Deshalb der Umweg über das Python-Skript.

(Dieses Skript funktioniert unter KDE 4.3.4, andere Versionen hab ich nicht getestet. Wäre möglich, dass die Funktion dann andere Paramter frisst)

Kategorien:Linux Tags:, , , , , , ,
  1. chris
    26. April 2010 um 10:18 | #1

    does not work for me in KDE 4.4.2

    …but this works:

    kdialog –title “Testtitle” –passivepopup “Message” 10

  2. 27. April 2010 um 00:06 | #2

    Yes, I think the KNotify API has changed with KDE 4.4. You can use the qdbus command to find out which parameters of the event method have been changed.

    I already knew of the kdialog passivepopup solution, but i find it a bit ugly and the message is gone forever if you don’t happen to sit before the computer when it pops up. KNotify saves the message, so you can read it later.

  1. Keine Trackbacks bisher.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Log Out / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Log Out / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Log Out / Ändern )

Verbinde mit %s

Follow

Get every new post delivered to your Inbox.