Run a command in terminal/iterm2 when an encrypted usb partition is mounted I'm not sure if this is possible.

I have an encrypted partition on a USB drive, when I mount it I want to run a script in iTerm2 or Terminal app.
Im not certain it will work for this, but I would suggest looking into AppleScript. I know you can use it to run Terminal commands, but I don't know if there is a way to detect when A flash drive is mounted.