You are not logged in.
I recently wrote a script to toggle bluetooth on and off and display a message using dunst, with the intent of binding it to a key using sxhkd. Here's the script:
#!/bin/sh
# bluetooth_toggle.sh - toggles bluetooth and outputs notification via dunst
# get bluetooth status: 0 if unblocked, 1 if blocked
blocked="$(rfkill list bluetooth | grep -c "yes")"
# arbitrary (but unique) nessage ID so it overwrites properly
msg_id="71112"
# block or unblock and show proper notification
if [ $blocked == "0" ]; then
rfkill block bluetooth
dunstify -a "bluetooth_toggle.sh" -u low -r "$msg_id" "bluetooth: off"
else
rfkill unblock bluetooth
dunstify -a "bluetooth_toggle.sh" -u low -r "$msg_id" "bluetooth: on"
fiThe script works well when called from the command line, toggling bluetooth being blocked and unblocked (confirmed by rfkill list bluetooth) and showing the message via dunst. However, when the script is run via a keybinding in sxhkd, the dunst message will only show "bluetooth: on" if it is currently off, or "bluetooth: off" if it is currently on-- and the status of bluetooth doesn't change in rfkill list bluetooth.
It appears that the script is working correctly except for the lines that actually block and unblock bluetooth (I would guess because the permission is denied). My user is added to the rfkill group (which allows me to run the script without issues from the terminal), but sxhkd is somehow not able to run it with correct permissions. How could I change this to allow sxhkd to execute rfkill? Or am I wrong and there is another issue entirely?
Last edited by locke (2020-12-24 18:54:21)
Offline
Edited title to better reflect my issue. Any ideas on how to give sxhkd permission to run rfkill?
Offline