From 936dbb039c2ac8b992b75b5f6720cd3eb62d0549 Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Thu, 9 Apr 2020 17:43:34 +0200 Subject: [PATCH] dunstctl: Print help message on dbus communication failure --- dunstctl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dunstctl b/dunstctl index 070eaf3..fca714c 100755 --- a/dunstctl +++ b/dunstctl @@ -1,6 +1,6 @@ #!/bin/sh -set -eu +set -u DBUS_NAME="org.freedesktop.Notifications" DBUS_PATH="/org/freedesktop/Notifications" @@ -24,17 +24,26 @@ show_help() { help Show this help EOH } +dbus_send_checked() { + dbus-send "$@" + rc="$?" + if [ "$rc" -eq "1" ]; then + echo "Failed to communicate with dunst, is it running? Or maybe the version is outdated." >&2 + echo "Hint: You can try 'dunstctl debug' as a next debugging step." >&2 + exit 1 + fi +} method_call() { - dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "$@" + dbus_send_checked --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "$@" } property_get() { - dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_PROP}.Get" "string:${DBUS_IFAC_DUNST}" "string:${1}" + dbus_send_checked --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_PROP}.Get" "string:${DBUS_IFAC_DUNST}" "string:${1}" } property_set() { - dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_PROP}.Set" "string:${DBUS_IFAC_DUNST}" "string:${1}" "${2}" + 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 || \