Autoplay CD with shell script not working

I tweaked this nifty nugget from sideshowbob for the Nanosound CD plugin, but can’t get the autoplay. I think it’s because of a longer delay for Volumio CD items to become available. Running the playcd.sh script works and plays the CD. Could anybody help me with this? ta

/home/volumio/playcd.sh

#!/bin/bash
sleep 5m
curl localhost:3000/api/v1/v1/browse?uri=audiocd | jq  '.navigation.lists[0].items' > myjson.txt
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=clearQueue
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/addToQueue --data "$(cat myjson.txt)"
# curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=volume&volume=50
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=play

/etc/udev/rules.d/99-local.rules

KERNEL=="sr[0-9]", ACTION=="change", ENV{ID_CDROM_MEDIA}=="1", ENV{ID_CDROM_MEDIA_STATE}!="blank", RUN+="/home/volumio/playcd.sh &"

Got this to work finally!

Just create a helper script file
/home/volumio/udev-playcd.sh (don’t forget to chmod +x it!)

#!/bin/bash
echo /home/volumio/playcd.sh | at now

/etc/udev/rules.d/99-local.rules

KERNEL=="sr[0-9]", ACTION=="change", ENV{ID_CDROM_MEDIA}=="1", ENV{ID_CDROM_MEDIA_STATE}!="blank", RUN+="/home/volumio/udev-playcd.sh &"

Then your /home/volumio/playcd.sh is…

#!/bin/bash
curl localhost:3000/api/v1/v1/browse?uri=audiocd | jq  '.navigation.lists[0].items' > myjson.txt
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/addToQueue --data "$(cat myjson.txt)"
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=volume&volume=50
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=play&N=1
eject -x 4 /dev/cdrom

The eject command is optional—prevents my CD drive overspinning noisily; credit nanomesher