Giter Club home page Giter Club logo

Comments (18)

xPMo avatar xPMo commented on September 12, 2024 3

Alternative: makoctl get_actions or similar and then the user can script around its output.

from mako.

zetorian avatar zetorian commented on September 12, 2024 2

perhaps it would be better to add a configuration option for a choosing command to run. ie "--<whatever_want_to_call_it>=dmenu | rofi | whatever else" so that it is possible to support wayland native dmenu alternatives as they appear without a major rewrite.

from mako.

dg10a avatar dg10a commented on September 12, 2024 1

Sorry, my comment wasn't very clear. I was using this revision, which worked with dunstify --action=$'key\n\n,val\n\n' "Test" but not with dunstify --action "key\n\n,val\n\n" "Test".

Both work now with the latest revision.

from mako.

adonespitogo avatar adonespitogo commented on September 12, 2024 1

Sorry for spamming, but I got it working by adding this line to mako config:

# ~/.config/mako/config
on-notify=exec makoctl menu wofi -d -p 'Choose Action: '

from mako.

emersion avatar emersion commented on September 12, 2024

Sure

from mako.

emersion avatar emersion commented on September 12, 2024

That would be nice too. Maybe we want both to be able to click on a notification to open the menu?

from mako.

dg10a avatar dg10a commented on September 12, 2024

In case it's useful to anyone, here's a script to handle notification actions with makoctl list and makoctl invoke. You can swap out rofi for your preferred menu.

#! /bin/sh

while true
do
    notifications=$(makoctl list)
    actions=$(echo $notifications | jq '.data[0][0].actions.data')
    if [ $(echo $actions | jq 'type') == "\"object\"" ] && [ $(echo $actions | jq 'length') != "0" ]; then
        selection=$(echo $actions | jq 'values[]' | sed 's/" "/"\n"/g' | sed 's,.\(.*\).$,\1,g' | rofi -p "Select notification action" -dmenu)
        if [ -n "$selection" ]; then
            selection_key=$(echo $actions | jq -r --arg sel "$selection" 'to_entries[] | select(.value == $sel) | .key')
            makoctl invoke $selection_key
        fi
        makoctl dismiss
    fi
    sleep 0.5
done

from mako.

xPMo avatar xPMo commented on September 12, 2024

Why is it wrapped in a while true ... sleep?

Also, here's an alternate script, moving logic into jq and using jq --exit-status:

if actions_object="$(makoctl list | jq -re '.data[0][0].actions.data | if length > 0 then . else false end')"; then
	makoctl invoke "$(jq -rn --arg sel "$(
			jq -rn "$actions_object|values[]" |
			rofi -dmenu -p "Select action: "
		)" \
		"$actions_object|to_entries[]|select(.value == \$sel).key"
	)"
fi

However, I think this is possible without requiring the user to have jq (use busctl without -j), I'll work on a makoctl patch for --dmenu [dmenu-program] [[args]]

EDIT: It is possible, but doing it in POSIX sh without arrays makes it pretty clunky.

from mako.

dg10a avatar dg10a commented on September 12, 2024

Thanks @xPMo, your script is much cleaner. I was using the script as a background process to intercept actionable notifications, hence the while true ... sleep.

Maybe --select-action of --dmenu?


EDIT: Here's what I'm using now. I added the check because rofi can return without a value.

bindsym $mod+a exec mako-select-action rofi -dmenu -p "Select action"

#! /bin/sh
# mako-select-action

if actions_object="$(makoctl list | jq -re '.data[0][0].actions.data | if length > 0 then . else false end')"; then
	selection="$(jq -rn --arg sel "$(
			jq -rn "$actions_object|values[]" |
			$@
		)" \
		"$actions_object|to_entries[]|select(.value == \$sel).key"
	)"
	if [ -n "$selection" ]; then
		makoctl invoke $selection
	fi
fi

from mako.

xPMo avatar xPMo commented on September 12, 2024

I found out during the course of writing the POSIX+no-jq variant that an action's key/value can have newlines or other difficult characters. busctl will print them as C-style escapes, so what I did is leave them escaped (that means you see action with\nescaped newlines in dmenu/rofi/etc.), and then fix them at the end:

if [ -n "$selection" ]; then
    # The selection may contain C escape sequences, use printf %b to evaluate them.
    # Due to how command substitutions occur, trailing newlines are mangled.
    # Append another character to prevent this.
    selection="$(printf '%b:' "$selection")"
    makoctl invoke "${selection%?}"
fi

You can test this with dunstify --action=$'key\n\n,val\n\n'.

from mako.

xPMo avatar xPMo commented on September 12, 2024

I do encourage anyone to review my POSIX sh script. I would like to contribute it in some form to mako, but it would be wise to make sure all the following hold:

  • The best way to handle multiple lists in sh is to set -- them together, keeping track of the length/offset of each. EDIT: I found a better way. 🙂
  • It correctly evaluates all C escape sequences provided by busctl.
  • The obtuse sh boilerplate is commented clearly enough for future maintenance.
  • @emersion thinks it would make a good fit either in makoctl or separately as contrib/bin/makomenu.

from mako.

dg10a avatar dg10a commented on September 12, 2024

Your example isn't working for me. When I use dunstify --action "key\n\n,val\n\n" "Test" with your escape functionality the action isn't received.

The same thing happens with your POSIX sh script. I think busctl is actually expecting the escaped string.

EDIT: Correction, your example works but it breaks this case.

from mako.

xPMo avatar xPMo commented on September 12, 2024

your example works but it breaks this case.

Care to explain exactly what --action breaks as a comment over there?

(In case you aren't aware, you can stay updated with any changes I make to the script:)

git clone 'https://gist.github.com/xPMo/462936ca0e86f3697a6365b2be02525d' makomenu

from mako.

niksingh710 avatar niksingh710 commented on September 12, 2024

Thanks @xPMo, your script is much cleaner. I was using the script as a background process to intercept actionable notifications, hence the while true ... sleep.

Maybe --select-action of --dmenu? EDIT: Here's what I'm using now. I added the check because rofi can return without a value.

bindsym $mod+a exec mako-select-action rofi -dmenu -p "Select action"

#! /bin/sh
# mako-select-action

if actions_object="$(makoctl list | jq -re '.data[0][0].actions.data | if length > 0 then . else false end')"; then
	selection="$(jq -rn --arg sel "$(
			jq -rn "$actions_object|values[]" |
			$@
		)" \
		"$actions_object|to_entries[]|select(.value == \$sel).key"
	)"
	if [ -n "$selection" ]; then
		makoctl invoke $selection
	fi
fi

This is nice but what i am trying to acheive is
listing all notifications from history in rofi and showing the title and summary in the rofi msg box at time of scrolling through them and as soon as i select the notification it shows me the available action with it.
i am unable to figure out how to incoke action from the history of notifications
I mean how can i access the previous notification action

from mako.

emersion avatar emersion commented on September 12, 2024

Once a notification has been dismissed, I don't think it's possible to invoke an action on it per the spec. NotificationClosed invalidates the notification ID.

from mako.

niksingh710 avatar niksingh710 commented on September 12, 2024

Once a notification has been dismissed, I don't think it's possible to invoke an action on it per the spec. NotificationClosed invalidates the notification ID.

Aah isn't there any hack around it to keep it available for the x amount of history notification?

from mako.

adonespitogo avatar adonespitogo commented on September 12, 2024

Hi, I'm new to hyprland and using mako as my notification daemon. I'd like to know if anyone knows how to handle bluetooth pairing confirmation? Mako is showing confirmation code but I have no way to click to confirm the pairing request. Any advise would be appreciated.

from mako.

adonespitogo avatar adonespitogo commented on September 12, 2024

I was able to confirm bluetooth connection using the example in the PR:

makoctl menu wofi -d -p 'Choose Action: '

But I had to manually type this in the terminal while the notification is still active. I'd like to know how to automatically invoke this using mako config.

from mako.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.