How do I use Emacs's DBUS interface?

后端 未结 4 1530
Happy的楠姐
Happy的楠姐 2021-02-07 20:17

I looked up the dbus package and it seems like all of the functions are built-in to the C source code and there\'s no documentation for them.

How do I use the dbus

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 20:41

    Here is a safe way to test for dbus capabilities:

    (defun dbus-capable ()
      "Check if dbus is available"
      (unwind-protect
          (let (retval)
            (condition-case ex
                (setq retval (dbus-ping :session "org.freedesktop.Notifications"))
              ('error
               (message (format "Error: %s - No dbus" ex))))
            retval)))
    

    And here is a way to send a dbus notification:

    (defun mbug-desktop-notification (summary body timeout icon)
      "call notification-daemon method METHOD with ARGS over dbus"
      (if (dbus-capable)
          (dbus-call-method
           :session                                 ; Session (not system) bus
           "org.freedesktop.Notifications"          ; Service name
           "/org/freedesktop/Notifications"         ; Service path
           "org.freedesktop.Notifications" "Notify" ; Method
           "emacs"
           0
           icon
           summary
           body
           '(:array)
           '(:array :signature "{sv}")
           ':int32 timeout)
        (message "Oh well, you're still notified")))
    

提交回复
热议问题