Script to detect if CD exists

Hi, I’m struggling to write a script that will detect if a cd is mounted. Tried to use “Folder actions” with a line like “if exists disk “my cd” then” to make it work but a mounted CD doesn’t seem to be a desktop item.
Thank you.


you have to watch the folder /Volumes.
A very smart solution is a launchd agent, take a look at the very helpful article of Craig Smith