Can I script actions while screensaver is engaged and a USB device is attached? I have a Mac mini running Mojave that starts a screensaver at login.

The screensaver is with password prompt, meaning that until a password is entered, it will not show the desktop.  I only have the screen saver enabled; power saver is set to not go to sleep.

I'm checking the machine with a Remote Desktop service (DWService) and browsing the file system. The USB Drive I attached did not mount. 

Currently I have to 


Enter screensaver password
detach USB
reattach USB


I would like to avoid this behavior, as I use folder action automation to start some process when I plug a USB storage with a magic file present on that drive. 

Does anyone know how to fix this?
Finder actions / folder actions are blocked while the screensaver is engaged, so you will need another solution for automation if you need it running while locked. 


https://superuser.com/questions/1516438/folder-actions-and-screensaver-issue


Your stub code seems well designed to start to learn, but perhaps a different automation tech is needed for your end goals?