Missive

> Published on Sun, 5 Jan 2025, 16:01> Updated on Wed, 8 Jan 2025, 19:05

The missive realm allows you to send information that will be displayed by simple-bar with its local notification system.

You can send a curl request with a POST method along a json body containing the following information:

  • content: Mandatory. The content of your notification.
  • side : Optional. "right" or "left". Default is "right".
  • delay: Optional. A number of milliseconds. Set it to 0 if you want to display a persistent notification. default is 5000.

Examples:

shell
# Send a notification containing "This is a notification".
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"content":"This is a notification"}' \
  http://localhost:7776/missive/push
shell
# Send a notification containing "This is a notification" for a duration of 10 seconds on the left side of simple-bar.
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"content":"This is a notification", "side": "left", "delay": 10000}' \
  http://localhost:7776/missive/push

As you can see, it can be a bit verbose. You can simplify the command by removing the --request flag as it is implied by the -- data flag. You can also use the -H flag instead of --header an -D instead of --data.

You can also create a function wrapping this call thus simplifying the process of send missives to simple-bar:

shell
send_missive() {
  content=$1
  side=$2
  delay=$3

  if [ -z "$content" ]; then
    echo "Content is required."
    return 1
  fi

  data="{\"content\": \"$content\"}"

  if [ -n "$side" ]; then
    data="{\"content\": \"$content\", \"side\": \"$side\"}"
  fi

  if [ -n "$delay" ]; then
    data="{\"content\": \"$content\", \"delay\": $delay}"
  fi

  if [ -n "$side" ] && [ -n "$delay" ]; then
    data="{\"content\": \"$content\", \"side\": \"$side\", \"delay\": $delay}"
  fi

  curl -H "Content-Type: application/json" -d $data http://localhost:7776/missive/push
}

This shell snippet is a basic example, feel free to adjust and optimize it if necessary.

Usage :

shell
# Send a notification containing "This is a notification" for a duration of 10 seconds on the left side of simple-bar.
send_missive "This is a notification" "left" 10000
Something is wrong in this documentation? Please open an issue on GitHub in simple-bar-server repo.