You could connect to OBS's WebSocket server. It already has that hook.
View attachment 98366
Or you could use the Advanced Scene Switcher plugin to do almost anything you want in response to anything:
This plugin will allow you to automate various tasks using "Macros". Macros consist of a list of conditions under which a list of actions will be performed. Examples and guides can be found in the wiki. Feel free to contribute! If you run...
obsproject.com
In your case, it might look something like this:
View attachment 98365