Categorygithub.com/z3ntu/go-dbus
repositorypackage
0.0.0-20170220120108-c022b8b2e127
Repository: https://github.com/z3ntu/go-dbus.git
Documentation: pkg.go.dev

# README

Documentation

Look at the API on GoPkgDoc.

Installation

go get launchpad.net/go-dbus/v1

Usage

An example

// Issue OSD notifications according to the Desktop Notifications Specification 1.1
//      http://people.canonical.com/~agateau/notifications-1.1/spec/index.html
// See also
//      https://wiki.ubuntu.com/NotifyOSD#org.freedesktop.Notifications.Notify
package main

import "launchpad.net/go-dbus/v1"
import "log"

func main() {
    var (
        err error
        conn *dbus.Connection
    )

    // Connect to Session or System buses.
    if conn, err = dbus.Connect(dbus.SessionBus); err != nil {
        log.Fatal("Connection error:", err)
    }

    // Create an object proxy
    obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")

    // Call object methods.
    reply, err := obj.Call("org.freedesktop.Notifications", "Notify",
        "dbus-tutorial", uint32(0), "",
        "dbus-tutorial", "You've been notified!",
	[]string{}, map[string]dbus.Variant{}, int32(-1))
    if err != nil {
        log.Fatal("Notification error:", err)
    }

    // Parse the reply message
    var notification_id uint32
    if err := reply.GetArgs(&notification_id); err != nil {
        log.Fatal(err)
    }
    log.Print("Notification id:", notification_id)
}