Skip to content

Instantly share code, notes, and snippets.

@lgaggini
Last active May 24, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lgaggini/51a35f363b7f1966971e869f3fbb5335 to your computer and use it in GitHub Desktop.
Save lgaggini/51a35f363b7f1966971e869f3fbb5335 to your computer and use it in GitHub Desktop.
Simple wrapper bash script to create notification feeding naughty by awesome-client
#! /bin/bash
# Author: Lorenzo Gaggini
# Version: 0.2
#
# Create a naughty awesome wm notification by title
# and message on secondary (big) screen
# init env for cron/at execution
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
export DISPLAY=:0
# check input
if [ "$#" -ne 2 ]; then
echo "usage: naughty-send title message"
exit 1
fi
# parse input
TITLE=$1
MSG=$2
# init naughty
/usr/bin/echo "naughty = require(\"naughty\")" | /usr/bin/awesome-client
# feed awesome-client
/usr/bin/echo "naughty.notify({title = \"$TITLE\", text = \"$MSG\", screen = screens, timeout = 0})" | /usr/bin/awesome-client
@raievsky
Copy link

Just in case someone is interested, two functions that can be used in conjunction to show and the hide a naughty notification from bash:

initString="naughty = require(\"naughty\");"

notifyString="notification = naughty.notify({ title = \"Achtung\", text = \"You're idling\", timeout = 0 }); return(notification.id);"

NotificationId=""

notifyUser()
{
   answer=`echo $initString $notifyString | awesome-client`

   NotificationId=`echo $answer | sed -e 's/^[[:blank:]]*//' | cut -d' ' -f 2`

   # echo "Notification requested. Answer: [$answer]. Notification id: [$NotificationId]"

}

removeNotification()
{

   getByIdString="
      function getById(id)
         -- iterate the notifications to get the notfications with the correct ID
         for p,pos in pairs(naughty.notifications[1]) do
            for i,notification in pairs(naughty.notifications[1][p]) do
               if notification.id == id then
                  return notification
               end
            end
         end
      end
   "
   destroyString="naughty.destroy(getById($NotificationId));"

   echo "$initString $getByIdString $destroyString" | awesome-client

}

notifyUser
removeNotificatio
```n

Only works for notifications on first screen, which is the one notification appears by defaults.
Hope this help.
Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment