How to detect Stage Manager state

Continuing the discussion from Ventura Beta - detect status of Stage Manager:

I just [stumbled upon a way to enable/disable Stage Manager from the command line and it can be easily used to read the current state, I just don't know how to use as trigger.

To read the current state:

defaults read GloballyEnabled

And to turn it on or off:

defaults write GloballyEnabled -bool [true|false]

Sharing it in case it helps anyone.