Trigger macro when a certain display gets connected (Cam Link 4k)

Hi guys,

I would like to run an automation as soon as a certain display gets connected to mac.
The display is not recognized as usb device but as display. So I would need a trigger that:

  • Recognizes a certain display (not all of them, so the count function doesn't work)

After searching through the forums I couldn't find a way.
So why on earth would you need a thing like that?

Real world use case
I do livestreaming on several macs. One of them is a macbook air.
As soon as I connect a "Elgato Cam Link 4k" to this macbook air, I would like it to run some actions.
The Cam Link gets connected through usb bus it not recognized as usb device anywhere in the systems report of the macbook air (m1 version). BUT it shows as a Display with the name "Cam Link 4k".

Is there a way to create a trigger that activates as soon as the display "INSERT DESIRED DISPLAY NAME HERE" gets connected? Since I have several displays monitors on this device, it should not trigger with any of the others.

Thanks in advance for your automation wizardry.

Your wizardry apprentice

Julian

1 Like

Searching the KM wiki gave me this: trigger:Display Layout Changed [Keyboard Maestro Wiki]

The first paragraph of this reads “The Display Layout Changed trigger (v9.0+) executes when the display layout changes, for example when you rearrange your monitors, add or remove a monitor, or change screen resolutions.”

So perhaps you might want to investigate using this trigger and see what it gives you?

Hi @tiffle,

great idea. I tested it already.
The display layout change trigger has no effect here, since the Cam Link only mirrors the whole display of the macbook, so nothing changes in the layout.

Thanks anyways, love the creativity.

I wasn’t so much interested in the change to display layout, but the adding of your display as you were asking originally. Are you saying that this trigger doesn’t notice when you add/connect your display?

Correct. I have the following setup:

  • Display layout change trigger
  • Show notification (to see if the macro gets triggered)

When I plug in the Cam Link through USB C I can see a mirrored display in the system preferences but the macro does not get triggered.

EDIT
I just saw that the notifications worked but did not get shown.
So the display layout change has been detected and the trigger fired.

Is there a way I can do a "If Then Else" to make sure it only fires if the Cam Link got attached (not any other monitor)? Maybe through a environment variable?

You can try displaying %TriggerValue% and see if it contains information about what caused the trigger. I would hope it might at least mention your display and that it was connected.

I’d use a Display Text in a window action - that way you’ll have time to see the information, as opposed to a brief notification.

I’d show you a macro but I’m away from my Mac right now.

The %TriggerValue% shows "Added,Enabled,Mirrored,Shape,Mode" when the Cam Link gets connected, so its a generic info.

Well, the fact that it contains “Added” and it triggered just after you connected your display tells you the trigger relates to connecting that display. Do you connect/disconnect other displays at all, or just that one in particular? If it’s only the Cam Link then your macro could could have an If action along the lines of:

If %TriggerValue% contains “Added”
Then do Cam Link connected stuff
Otherwise do nothing

Does that make sense?

Yes, makes total sense.
Unfortunately I have 2 challenges with that:

  1. As posted above I connect other displays to the macbook as well but this trigger should only run for the cam link (it will mess with background software in the end which should not happen with other displays).

  2. I sync my macros for convenience between my macs and this trigger should only run on the macbook air, not on other macs when things get connected there (even a cam link connected to another mac should not trigger anything there)

Thanks for looking into this, I really appreciate your time and ideas.

At the top of your macro test the value of the KM token %MacName% - if it is not your MacBook Air, then quit the macro.

You actually said

which I took to mean they were permanently connected; you didn’t answer my question

If you’re saying you do connect/disconnect other displays as well as the Cam Link, then I’m not sure how to distinguish between them other than by possibly using the Screen related tokens. Have a look in the wiki here token:Screen [Keyboard Maestro Wiki].

I’m off now for some kip, maybe you’ll make some headway now or someone else can chip in. Cheers!

I did a quick video to show the current status and challenges:

Thanks for looking into it.

I didn’t need to watch your whole video - it is clear why you’re not getting the result you expect: neither %TriggerValue% nor %MacName% are variables so you can’t use them as if they are; they are both text tokens, therefore you need to use a text condition in your If action.

So at 1:38 in your video, for example, you should be choosing to add a text condition, not a variable condition and you should be specifying %TriggerValue% including the percent signs (and the same goes for the %MacName% token).

You should read up about how to use KM Text Tokens in the KM wiki here manual:Tokens [Keyboard Maestro Wiki].

I’m once again away from my Mac so I can’t show you a snippet from an actual macro, but there are plenty of examples of text token usage scattered about this forum and the wiki pages too.

Next time I’m at my desk I’ll post a macro example for you to see should you not be able to utilise the advice I’ve just given you. Let me know how you’re getting on.

1 Like

Hi @WinWinWin, have a look at this… BTW you need to change the macro trigger to display changed for it to work in your case.

Test display trigger.kmmacros (3.5 KB)
Test display trigger

Don't have time to walk you through this. Let me know how you get on...

1 Like

Hi @tiffle

Thanks for your example.

I tested a few things and went with a "hybrid automation" now, doing some of the things manually.

Since I could not figure out how to automatically identify if it is really the cam link and not another display that got connected, I created a popup with a run/stop request.

Thanks for your help, I learned a lot about tokes which will be very helpful moving forward.

Julian

1 Like