You are not logged in.
I have a simple bash script for turning screen on/off. Here it is. File brightness-toggle.sh:
#!/bin/bash
if ! [[ -v SCREEN_TOGGLE ]]; then
export SCREEN_TOGGLE=1
fi
if [[ $SCREEN_TOGGLE = 1 ]]; then
brightnessctl -s; brightnessctl set 0%; SCREEN_TOGGLE=0
elif [[ $SCREEN_TOGGLE = 0 ]]; then
brightnessctl -r; SCREEN_TOGGLE=1
fiIt is set for hotkey in my .sxhkdrc file:
#
# settings for fn+f keys
#
XF86MonBrightnessUp
brightnessctl set +5%
XF86MonBrightnessDown
brightnessctl set 5%-
XF86Display
brightness-toggle.sh
XF86AudioRaiseVolume
increase-volume.sh
# pactl set-sink-volume 0 +5%
XF86AudioLowerVolume
pactl set-sink-volume 0 -5%
XF86AudioMute
pactl set-sink-mute 0 toggle
XF86Bluetooth
blueberryHowever, when I use it from hotkey, it can't change value of $SCREEN_TOGGLE, thus it doesn't work properly (but it does change brightness though). Also, when I use it directly from terminal it only works properly when I call it as
. brightness-toggle.shTrying to run script from sxhkd with "." before it didn't solve the problem.
This may be very stupid question but I would appreciate help with it.
Last edited by EgoRed (2025-06-05 20:30:51)
Offline
This isn't going to work that way. You can't export your shell environment up the chain into sxhkd, which is the process that would have to know about this. Create a file in /tmp and reading the true or false value from there (or just checking for existence of the file and removing it again) is likely more fruitful for what you're attempting.
It works in the terminal because the terminal itself is changing it's own environment. Once your script has completed any environments you're exporting there will be gone.
Last edited by V1del (2025-06-05 18:25:51)
Offline
This isn't going to work that way. You can't export your shell environment up the chain into sxhkd, which is the process that would have to know about this. Create a file in /tmp and reading the true or false value from there (or just checking for existence of the file and removing it again) is likely more fruitful for what you're attempting.
It works in the terminal because the terminal itself is changing it's own environment. Once your script has completed any environments you're exporting there will be gone.
Thank you so much for the explanation! I will definitely try this approach with temp file.
Offline
Skip the state, query "brightnessctl g", if that's the equivalent of "0%" (you'll get an absolute value), restore the previous value.
Are you btw. looking for "xset dpms force off"?
Offline
Skip the state, query "brightnessctl g", if that's the equivalent of "0%" (you'll get an absolute value), restore the previous value.
I was just thinking about it. Although using separate variable may allow me to extend this script in the future to consider separately is screen on/of and it's brightness.
Are you btw. looking for "xset dpms force off"?
But maybe that is exactly the thing I am thinking about, thanks!
Offline