You are not logged in.
hello, as the tittle say, I'm trying to do, is: automaticlly turn Off the notebook screen when I plug in a HDMI cable to a TV. To do so, I followed this Arch Wiki's Automatically switch audio to HDMI to switch the audio from speakers to HDMI, it works perfect, now I tried to add this Script Toggle external monitor does not turn Off the Notebook's screen.
this is the script that the Service runs when the HDMI is plugg/unplugged: "/usr/local/bin/hdmi_sound_toggle.sh"
#!/bin/bash
intern=LVDS1
extern=HDMI1
USER_NAME=fajung
USER_ID=$(id -u "$USER_NAME")
HDMI_STATUS=$(cat /sys/class/drm/card0/*HDMI*/status)
export PULSE_SERVER="unix:/run/user/"$USER_ID"/pulse/native"
if [[ $HDMI_STATUS == connected ]]
then
sudo -u "$USER_NAME" pactl --server "$PULSE_SERVER" set-card-profile 0 output:hdmi-stereo+input:analog-stereo
sudo -u "$USER_NAME" DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USER_ID/bus notify-send 'Cable HDMI' "Conectado" -i "/usr/share/icons/h$
else
sudo -u "$USER_NAME" pactl --server "$PULSE_SERVER" set-card-profile 0 output:analog-stereo+input:analog-stereo
sudo -u "$USER_NAME" DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USER_ID/bus notify-send 'Cable HDMI' "Desconectado" -i "/usr/share/icon$
fi
sleep 2
if xrandr | grep "$extern disconnected"; then
xrandr --output "$extern" --off --output "$intern" --auto
else
xrandr --output "$intern" --off --output "$extern" --auto
fi
It should Turn Off the notebook screen Off when I connect the HDMI cable, and turn it back On when the HDMI is disconnected, the Audio part of the script works fine.
Offline
And from where do you know that HDMI1 and LVDS1 are correct for your setup? And you likely will want to sudo -u "$USER_NAME" DISPLAY=:0 the xrandr commands as well. You will have to replace these with the correct identifiers for your setup, use
xrandr -q
Last edited by V1del (2017-09-22 11:56:48)
Offline
thanks. this is how it works(I think)-
#!/bin/bash
intern=LVDS1
extern=HDMI1
USER_NAME=fajung
USER_ID=$(id -u "$USER_NAME")
HDMI_STATUS=$(cat /sys/class/drm/card0/*HDMI*/status)
export PULSE_SERVER="unix:/run/user/"$USER_ID"/pulse/native"
if [[ $HDMI_STATUS == connected ]]
then
sudo -u "$USER_NAME" pactl --server "$PULSE_SERVER" set-card-profile 0 output:hdmi-stereo+input:analog-stereo
sudo -u "$USER_NAME" DISPLAY=:0 xrandr --output "$extern" --auto
sudo -u "$USER_NAME" DISPLAY=:0 xrandr --output "$intern" --off
sudo -u "$USER_NAME" DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send 'Cable HDMI' "Conectado" -i "/usr/share/icons/hicolor/256x256/devices/HDMI-256.png" -t 5000
else
sudo -u "$USER_NAME" pactl --server "$PULSE_SERVER" set-card-profile 0 output:analog-stereo+input:analog-stereo
sudo -u "$USER_NAME" DISPLAY=:0 xrandr --output "$intern" --auto
sudo -u "$USER_NAME" DISPLAY=:0 xrandr --output "$extern" --off
sudo -u "$USER_NAME" DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send 'Cable HDMI' "Desconectado" -i "/usr/share/icons/hicolor/256x256/devices/HDMI-256.Disconnected.png" -t 5000
fi
Offline
Don't hardcode user/display values but rather adapt https://gist.githubusercontent.com/Alad … tfile1.txt (you're likely not using xinit?)
Offline