At the time of writing there are no “Shortcuts-native” ways to cleanly live-detect a focus change, so any suggestion above is valid.
If that can be of any use, this thread talks about figuring out the current focus mode. That’s still not live detection though.
(it’s time for Apple to add Shortcuts Automation on macOS )