I have a script that executes perfectly fine manually, though two commands in particular are completely ignored by Cron (this is just a snippet):
sinkint=$(pacmd list-sinks | sed -n '/index\W [1-9]/p' | sed 's/.*://g;s/\W//g')
pacmd set-default sink $sinkint
pacmd set-sink-volume $sinkint 20%
Crontab
* * * * * /path/to/script arg1 >> /path/to/log
Error messages
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
You have to specify a sink name/index and a volume
Edit:
tried variables in script
export PULSE_SERVER=unix:/tmp/pulse-socket
export PULSE_COOKIE=/tmp/pa_cookie
socket in my /etc/pulse/default.pa
load-module module-native-protocol-unix socket=/tmp/pulse-socket
socket and cookie in my /etc/pulse/client.conf
default-server = unix:/tmp/pulse-socket
cookie-file = /tmp/pa_cookie
crontab -e
PULSE_SERVER=unix:/tmp/pulse-socket
PULSE_COOKIE=/tmp/pa_cookie
* * * * * /path/to/script arg1 2> /path/to/log
pacmd
needs some environment variables or such to find the server, at least the Arch Linux wiki mentionsPULSE_SERVER
andPULSE_COOKIE
. You may want to check that whatever it needs to find the daemon is available under cron, too.env | grep -i pulse
from a shell where the script works. You're probably missing an environment variable that is being set by pulseaudio in your session but not in the session run by cron.