Any way to use external display orientation as a trigger?

I have an external display. Specifically, an Apple Studio Display that I use with my MacBook Pro.

Is it possible to use this external display's orientation as a trigger?

Specifically, this would mean the ability to trigger macros when the display has been rotated from landscape/horizontal to portrait/vertical orientation, and separately the ability to trigger macros when the display has been rotated from portrait/vertical to landscape/horizontal orientation.

Mac OS itself automatically detects and adjusts when the Apple Studio Display is rotated, so I have to imagine this "status" is stored somewhere, and thus could potentially serve as a trigger?

1 Like

The Display Layout Changed trigger may work for this, as I know it catches adding and removing displays as well as resolution changes. So it might also catch orientation changes, but I’m not 100% certain. If it does, you could then use the Screen token, perhaps %Screen%External% to determine orientation and go from there.

1 Like

The display layout trigger works when I rotate the display! Awesome.

I looked at the screen tokens link you shared, but how would I use them to return the current external display orientation?

1 Like

For example, right now the token %Screen%Main% return 0,0,1512,982 (I’m using my MacBook screen as an example because I’m not at my desk and don’t have my external monitor hooked up, but you’ll get the idea).

That’s standard orientation: the first 0 indicates horizontal position, the second 0 the vertical position, 1512 is horizontal resolution and 982 the vertical resolution. Since I already know what my resolution is, then I would also know that if that same token returned 0,0,982,1512, then the screen is rotated, since the vertical resolution is now greater than the horizontal.

I would dare to say that anytime you a greater digit in the 4th position (again, vertical resolution) than what the 3rd digit returns, it’s rotated... but I’ve never really worked with rotated monitors so I can not guarantee that.

If you wanted a real simple test case, you don’t even need the entire token, you could use the token as an array, just extracting either the 3rd or 4th value from it and using that in a switch action, or if/then/else action. See my sample macro below for what would work on my external monitor; you would need to adjust the 2560 and 1440 to whatever your external monitor’s resolution is.

Download Macro(s): Determine external monitor orientation.kmmacros (3.9 KB)

Macro-Image

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
  • The user must ensure the macro is enabled.
  • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.6.3
  • Keyboard Maestro v11.0.2
2 Likes

Thanks as always, @cdthomer! This did the trick. Happy New Year.

1 Like

Glad it worked! Be safe out there today!

1 Like

In case anyone comes across this via search, here are a couple of macros that will detect the screen orientation on the screen that contains the active window and trigger actions conditionally based on vertical vs horizontal orientation:
https://github.com/rickgladwin/keyboard_maestro_macros

(I used the resources from this thread when putting these together, so thanks!)

1 Like