Use focus mode change as a trigger for Keyboard Maestro Macro

Maybe you could monitor the Assertion.json file? If I understand correctly from the discussion and code in the thread below, it should change to contain details about the latest focus mode (by ID at least) when the focus mode is changed. When a change is detected (you could monitor a folder and then explicitly check timestamp vs current time on the file for example), then use the JXA script to read the current focus mode, and take action accordingly.

Depending on your mystery use case, maybe flip it around and use Keyboard Maestro macros to trigger focus changes (call a Shortcut to set focus mode) and run whatever it is you want it to do. I would imagine that is a simpler approach, if your use case supports it (e.g. you are not triggering a focus change from the Mac or another device).

Hope that helps.

1 Like