Scripts on mac. Auto execute from USB? I have written a simple script for macbook and later found a program called platypus which makes an .sh file to an .app

Now I want to ask if it's possible to launch that app from the USB automatically as soon as it's plugged in?

And if somehow yes. Does it also work if the mac is closed or just in login Screen?
No, this wont work. This is one of the advantages of macOS, it does not execute stuff that is found on a USB drive.

I consider this a great deal when we talk about security.

However there are devices that look like an USB thumb drive, but when plugged in expose themselves as a HID (Human Interface Device) and then execute keyboard shortcuts to run their exploits.

For example the USB Rubber Ducky Deluxe is such a device.