From Tiny Marten, 5 Months ago, written in Plain Text.
  1. #!/bin/bash
  2. # Desc: Use dbus itself to send notification message. Instead of notify-send or whathaveyou.
  3. # Usage: notify-send-gdbus [OPTION...] <SUMMARY> [BODY]
  4. #   -u, --urgency=LEVEL               Urgency level (low, normal, critical).
  5. #   -t, --expire-time=TIME            Expriry timeout in milliseconds.
  6. #   -a, --app-name=APP_NAME           App name for icon.
  7. #   -e, --exec                        Set the ACTION param to pass.†
  8. #   -i, --icon=ICON[,ICON...]         Icon file or stock iconname to display.
  9. #   -c, --category=TYPE[,TYPE...]     Notification category.
  10. #   -h, --hint=TYPE:NAME:VALUE        Extra crap to pass.
  11. #
  12. # Note: The --hint option field values are:
  13. #   TYPE        One of int, double, string or byte.
  14. #   NAME:VALUE  Names and vaules are paired. Standard‡† k,v pairs are:
  15. #                 urgency:byte, desktop-entry:ApplicationDesktopID,
  16. #                 category:string, image_data:(iiibiiay), x:int, y:int,
  17. #                 sound-file:string, suppress-sound:boolean.
  18. #
  19. # † Not used by notify send.
  20. # ‡ For more information, please visit:
  21. #     <http://www.galago-project.org/specs/notification/0.9/x344.html>
  22. #     <https://developer.gnome.org/glib/stable/gvariant-text.html>
  23. #
  24.  
  25.  
  26. gdbus call  --session --dest org.freedesktop.Notifications \
  27.   --object-path /org/freedesktop/Notifications \
  28.   --method org.freedesktop.Notifications.Notify \
  29.   "" "1" "" "$1" "${@//$1/}" '["", ""]' "{'0':<0>}" "int32 6000"
  30. #gdbus call  --session --dest org.freedesktop.Notifications \
  31. #  --object-path /org/freedesktop/Notifications \
  32. #  --method org.freedesktop.Notifications.CloseNotification 1
  33. #exit
  34.  
  35. msg(){ printf -- "%s\n" "$@"; }
  36. emsg(){ printf -- "%s\n" "$@" >&2; }
  37. bail(){ emsg "$@"; usage; exit 1; }
  38. usage(){ awk -F '# ' 'NR>2{print $2};$0==""{exit}' <"$0"; }
  39.  
  40. gvarfmt(){
  41.   local id
  42.   id="${2//[^[:alnum:]]/}${RANDOM#-}"
  43.   case "$1" in
  44.     list) prinf -- "[\"%s\", \"%s\"]" "${id}" "${2}";;
  45.     dict) prinf -- "{\"%s\": <%s>}" "${id}" "${2}";;
  46.     *) bail "E!: Missing format type option to \`gvarfmt\`";;
  47.   esac
  48. }
  49.  
  50. #UINT32 org.freedesktop.Notifications.Notify (STRING app_name, UINT32 replaces_id, STRING app_icon, STRING summary, STRING body, ARRAY actions, DICT hints, INT32 expire_timeout);
  51.  
  52. gdbus-call(){
  53.   local method
  54.   [[ -z "$1" ]] && bail "E:! something went wrong! just kidding.. dbus isnt working"
  55.   method="$1"; shift
  56.  
  57.   command gdbus call \
  58.     --session --dest org.freedesktop.Notifications \
  59.     --object-path /org/freedesktop/Notifications \
  60.     --method org.freedesktop.Notifications."$method" "$@"
  61. }
  62.  
  63. declare APPNAME REPLACEID ICON SUMMARY BODY EXPIREY optval
  64. declare -a ACTIONS HINTS OPTIONS NOTIFICATION
  65.  
  66. ACTION="0,0"
  67. HINT="0:0"
  68.  
  69. while (($#)); do
  70.  
  71.   if [[ "$1" =~ *(=)* ]]; then
  72.     optval="${1##*=}"; shift
  73.   else optval="$2"; fi
  74.  
  75.   case "$1" in
  76.     --help) usage; exit 0;;
  77.     -a|--app-name=*)
  78.       OPTIONS+=("APPNAME" "$optval"); shift; continue
  79.       ;;
  80.     -c|--category=*)
  81.       #OPTIONS+=("$optval"); shift; continue
  82.       emesg "W! The '--category' flag is not implemented yet"; shift; continue
  83.       ;;
  84.     -e|--exec)
  85.       OPTIONS+=("ACTION" "$optval"); shift; continue
  86.       ;;
  87.     -h|--hint=*)
  88.       OPTIONS+=("HINT" "$(gvarfmt dict "$optval")"); shift; continue
  89.       ;;
  90.     -i|--icon=*)
  91.       OPTIONS+=("ICON" "$optval"); shift; continue
  92.       ;;
  93.     -t|--time|--expiretim=*)
  94.       OPTIONS+=("EXIPERY" "$optval"); shift; continue
  95.       ;;
  96.     -u|--urgency=*)
  97.       OPTIONS+=("URGENCY" "$optval"); shift; continue
  98.       ;;
  99.     *)
  100.       OPTIONS+=("$@"); shift "$#"; break
  101.       ;;
  102.   esac
  103. done
  104.  
  105. for o in APPNAME REPLACEID ICON ACTION HINT EXPIRY; do
  106.   if [[ "${OPTIONS[$i]}" == "$o" ]]; then
  107.     NOTIFICATION+=("${OPTIONS[$i+1]}")
  108.   else NOTIFICATION+=""; fi
  109. done
  110. # appname, replaceid, icon, summary, body, action,       hint,        timeout
  111. # ""       "0"        ""    "txt"    ""    '["", ""]'   "{'':<0>}"    "int32 6000"
  112.  
  113.  
  114. gdbus-call Notify "${NOTIFICATION[@]}"
  115.  
  116.  
  117. gdbus-call CloseNotification 28
captcha