Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ distro's repositories, don't worry, it's not hard to build it yourself.
- wayland-protocols (optional, for recompiling protocols)
- xdg-utils (optional, xdg-open is the default 'browser' for opening URLs)
- jq (optional, for installed completions and tools in contrib)
- busctl (optional, for dunstctl rules and dunstctl history)

The names will be different depending on your [distribution](https://github.com/dunst-project/dunst/wiki/Dependencies).

Expand Down
30 changes: 20 additions & 10 deletions dunstctl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ DBUS_IFAC_DUNST="org.dunstproject.cmd0"
DBUS_IFAC_PROP="org.freedesktop.DBus.Properties"
DBUS_IFAC_FDN="org.freedesktop.Notifications"

die(){ printf "%s\n" "${1}" >&2; exit 1; }
die() {
printf "%s\n" "${1}" >&2
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
echo "DBUS_SESSION_BUS_ADDRESS is blank. Is the D-Bus session configured correctly?" >&2
fi
exit 1
}

show_help() {
# Below, each line starts with a tab character
Expand Down Expand Up @@ -44,6 +50,12 @@ show_help() {
help Show help
EOH
}

busctl_checked() {
command -v busctl >/dev/null 2>/dev/null || die "Command busctl not found"
busctl --user --json=pretty --no-pager call "${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_DUNST}" "$@"
}

dbus_send_checked() {
dbus-send "$@" \
|| die "Failed to communicate with dunst, is it running? Or maybe the version is outdated. You can try 'dunstctl debug' as a next debugging step."
Expand All @@ -61,9 +73,7 @@ property_set() {
dbus_send_checked --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_PROP}.Set" "string:${DBUS_IFAC_DUNST}" "string:${1}" "${2}"
}

command -v dbus-send >/dev/null 2>/dev/null || \
die "Command dbus-send not found"

command -v dbus-send >/dev/null 2>/dev/null || die "Command dbus-send not found"

case "${1:-}" in
"action")
Expand Down Expand Up @@ -151,16 +161,17 @@ case "${1:-}" in
"rules")
case "${2:-}" in
"" | --json)
busctl --user --json=pretty --no-pager call "${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_DUNST}" RuleList \
busctl_checked RuleList \
| {
if [ "${2:-}" = '--json' ]
then
cat
else
command -v jq >/dev/null 2>/dev/null || die "Command jq not found"
jq --raw-output '.data[][] | ["[\(.name.data)]"], [to_entries[] | select(.key != "name") | " \(.key) = \(.value.data)"] | join("\n")'
fi
} \
|| die "Dunst is not running."
|| die "Dunst is unreachable or the version is too old."
;;
*)
die "Unknown format \"${2}\". Please use either \"--json\" or no option at all."
Expand Down Expand Up @@ -205,7 +216,7 @@ case "${1:-}" in
;;
"debug")
dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_FDN}.GetServerInformation" >/dev/null 2>/dev/null \
|| die "Dunst is not running."
|| die "No notification manager is running."

dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_FDN}.GetServerInformation" \
| (
Expand All @@ -219,8 +230,8 @@ case "${1:-}" in
|| die "Dunst controlling interface not available. Is the version too old?"
;;
"history")
busctl --user --json=pretty --no-pager call org.freedesktop.Notifications /org/freedesktop/Notifications org.dunstproject.cmd0 NotificationListHistory 2>/dev/null \
|| die "Dunst is not running."
busctl_checked NotificationListHistory \
|| die "Dunst is not running or unreachable."
;;
"reload")
shift
Expand All @@ -234,4 +245,3 @@ case "${1:-}" in
;;
esac
# vim: noexpandtab

5 changes: 5 additions & 0 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,11 @@ static void dbus_cb_name_lost(GDBusConnection *connection,
DIE("Cannot acquire '"FDN_NAME"'.");
}
} else {
const char *env = getenv("DBUS_SESSION_BUS_ADDRESS");
if (STR_EMPTY(env)) {
LOG_W("DBUS_SESSION_BUS_ADDRESS is blank. Is the dbus session configured correctly?");
}

DIE("Cannot connect to DBus.");
}
exit(1);
Expand Down