Remote Control Trigger — Updated With Solution

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.

Here is current script.

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

  1. Disable checkbox "Always show Remote Management status in menu bar" in System Preferences > Sharing,
  2. 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.

Here is the revised macro.

1 Like

Hi,

Thanks for sharing your works.

I just got into this macro world and barely know how to operate shell scripts, so I referenced yours to run my displayplacer script via KM.

The script works good on terminal with the line like this

displayplacer "id:D5C1BFAE-CA1D-6490-3C92-70FD722C399A+1B92BA28-400C-D615-5AED-4950FF2471A2 res:1920x1200 hz:59 color_depth:8 scaling:off origin:(0,0) degree:0 "

But unfortunately nothing happened when using KM like below:

I suspect the cpu type that I'm using M1 and yours is Intel processor but I'm not really tech guy, so I just have a suspicious feeling.

Are there any tips that you can give?

When something works in Terminal but not in a KM action it's usually because you don't have the same PATH environment variables in both. To find the correct path, in Terminal type which <utilityName> -- in this case, which displayplacer.

I'm guessing you installed displayplacer with Homebrew -- in which case you should know that Homebrew has a different (more correct!) base install path on M1 processors than for the old Intels. It is now /opt/homebrew/bin, so you can probably change the start of the second line of your script to /opt/homebrew/bin/displayplacer.

2 Likes

Oh wow! Thanks!

It works smoothly as hell.

It's so simple why didn't I figured it out?

Thanks @Nige_S!