App won’t run when DVD is inserted

applescriptdvd

I have an older iMac running El Capitan. I want to run a shell script when a DVD is inserted. I used Script Editor to create an Applescript that runs the shell script. The Applescript is just

do shell script "sh /Users/shannon/bin/myscript"

I used System Preferences > CDs and DVDs to configure the action when a DVD is inserted to run the Applescript.

It didn't work, DVD Player still runs and the script doesn't.

I used Script Editor to save the script as an application and configured it to run the application.

Still didn't work.

I copied the application to /Applications and changed it to run that copy of the application.

Still didn't work.

I changed the ownership of the application to root (sudo chown -R root /Applications/myapp).

Still didn't work.

No matter what I do, my script/app won't run, and DVD Player runs instead.

What am I doing wrong?

If I run the app by double-clicking on it, it runs correctly and invokes my shell script, so I know the app itself is working correctly.

Do I need to do something special in or to my application to convince the OS that it's capable of running when a DVD is inserted?

(This is very similar to this much older question, which has no answer.)

I tried changing the configuration to open Text Edit when a DVD is inserted, and that didn't work either, so the problem has nothing to do with my program or my script. It appears that this feature just doesn't work at all.

Best Answer

I restarted my system and now this is working, it's invoking my app when the DVD is inserted. There's nothing in the instructions suggesting that a restart is required, but that seems to be the key to making this working. I didn't test whether logging out and logging back in would be sufficient.