Using cron to mute sound in Ubuntu 20.04
Wednesday, August 18th, 2021I wanted to turn off audio at night automatically using cron.
I saw suggestions to use amixer:
export DISPLAY=:0 && /usr/bin/amixer -D pulse sset Master,0 0%
but this gave an error:
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused
amixer: Mixer attach pulse error: Connection refused
This works, add this line to /etc/crontab:
* 23<tab>* * *<tab>jiml<tab>DISPLAY=:0.0 pactl --server unix:/run/user/1000/pulse/native set-sink-mute @DEFAULT_SINK@ true
and restart cron:
service cron restart
jiml is the user with the open desktop.
‘1000’ is the uid of user ‘jiml’, this can be found by:
ls /run/user
or
id -u jiml
and restart cron:
service cron restart
jiml is the user with the open desktop.
‘1000’ is the uid of user ‘jiml’, this can be found by:
ls /run/user
or
id -u jiml