Can I script actions while screensaver is engaged and a USB device is attached?
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?