I have been trying to trigger screen mirroring when remotely signing into macOS and watching for the agent ScreensharingAgent to launch, run, etc so I can have it switch all external monitors to mirror the main monitor but not having any luck.
Environment:
- macOS 12.3 / MBP 16" 2020 Intel.
- Keyboard Maestro Version 10.0.1
Configuration
- System runs 24/7; never sleeps
- Account locks after disconnecting a remote session.
- Screen management - bash script displayplacer
- Remote management - macOS app Screens.app 4
Any assistance would be appreciated.
Update Working Solution
Clarification of how Screen Sharing Session works. - Link.
After reviewing the above answer and some experimenting found a partially working solution.
Configuration
- Disable checkbox "Always show Remote Management status in menu bar" in System Preferences > Sharing,
- In Keyboard Maestro conditional if/else settings
2a. This Application: SSMenuAgent.app is "is running but not at the front"
That is the trigger setting that will show the Menu when someone is observing the mac. Additionally, I added a secondary check to make sure the "Screens Connection" agent is running (it only launches during an active session), keeping those two options conditional to ALL allows for both local network and remote connecting to trigger the mirroring. And prevents the trigger when Apple Support connects.