Sorry I didn't see this earlier.
Here is the script in its current form:
#! /bin/bash
set -euxo pipefail
printenv
export PULSE_RUNTIME_PATH="/run/user/1000/pulse/"
export DISPLAY=:0
read hdmi_status < /sys/class/drm/card0-HDMI-A-1/status
echo $hdmi_status
read hdmi_status2 < /sys/class/drm/card0-HDMI-A-2/status
echo $hdmi_status2
sleep 1
if [[ $hdmi_status == "connected" ]]; then
pacmd set-card-profile 0 "output:hdmi-stereo"
elif [[ $hdmi_status2 == "connected" ]]; then
pacmd set-card-profile 0 "output:hdmi-stereo"
else
pacmd set-card-profile 0 "output:analog-stereo"
fi
chk_presentation_mode="$(xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode)"
toggle_presentation_mode_on () {
(xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s "true")
}
toggle_presentation_mode_off () {
(xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -s "false")
}
if [[ $hdmi_status == "connected" ]]; then
if [[ $chk_presentation_mode == "false" ]]; then
notify-send -i gtk-dialog-info "Presentation mode is off"
toggle_presentation_mode_on
notify-send -i gtk-dialog-info "Presentation mode is now turned on"
else
notify-send -i gtk-dialog-info "Presentation mode is already on"
fi
elif [[ $hdmi_status2 == "connected" ]]; then
if [[ $chk_presentation_mode == "false" ]]; then
notify-send -i gtk-dialog-info "Presentation mode is off"
toggle_presentation_mode_on
notify-send -i gtk-dialog-info "Presentation mode is now turned on"
else
notify-send -i gtk-dialog-info "Presentation mode is already on"
fi
else
if [[ $chk_presentation_mode == "true" ]]; then
notify-send -i gtk-dialog-info "Presentation mode is on"
toggle_presentation_mode_off
notify-send -i gtk-dialog-info "Presentation mode is now turned off"
else
notify-send -i gtk-dialog-info "Presentation mode is already off"
fi
fi
When running in terminal as user it now works exactly as intended. I think the original problem was due to how I defined the chk_presentation_mode function. Now there is a new problem, though.
I would like it to automatically run when the HDMI display is connected. I am using this udev rule:
SUBSYSTEM=="drm", ACTION=="change", RUN+="/bin/bash /home/llogg/.scripts/hdmitoggle_trigger.sh"
which calls this script
#!/bin/bash
for dir in /home/*/
do
dir=${dir%*/}
sudo -u ${dir##*/} /home/llogg/.scripts/hdmitoggle.2.sh
done
I have to do that because udev can't directly affect pulseaudio, I guess. The audio switch works perfectly, but the presentation mode does not switch and none of the notifications are displayed. No terminal output because udev doesn't really run it in a terminal. Any ideas?