Target Display Mode when screen is locked

Hello,

Is it possible to run a script that starts\ends target display mode (toggling target display mode) when the screen is locked, without login in.

Thanks in advance,
Aviv