Copy 2FA code from received iMessage/Text on MacOS

Hi everyone, Is anyone aware of a script/app that can automatically copy the code from a 2FA text message on MacOS? On iOS, if you receive a code via text/iMessage, a horizontal menu appears with the code, and with an easy finger click, it will automatically populate the code field on the given app. Is there something similar on MacOS? Thanks!

… will automatically populate the code field on the given app

Maybe I’m missing something, but doesn’t this already automatically happen on MacOS too?

You probably need to have Text Message Forwarding enabled on your iPhone (Settings → Messages → Text Message Forwarding), and your Mac will need to be signed into the same AppleID account, but then you’re set.

My Mac is set up with the forwarding and I can see the message. Does it only work in Safari?