Tech Tips

Detecting When You’re “Away” or “Back” in Your Keyboard Maestro Macros

Your Mac knows the last time you moved the mouse or pressed a keyboard key. We can use this information in Keyboard Maestro to perform actions based on whether we’ve “gone away” from or have “come back” to our computer. I’m using this technique to set my status in Slack to “Away” if I step away from my computer for more than 10 minutes, and back to “Active” when I return. Here are a few quick examples that could use this same basic framework:

  • Automatically pause music if I step away
  • Show me a “Welcome back!” message when I return
  • Write the date/time to a log file the when I go away and when I return

Setup your macro with a “Periodically while logged in” trigger. In the example here I’m using 10 seconds because I want no more than 10 seconds to pass before my system detects that I’ve returned to my desk. The macro isn’t very CPU-hungry so 10 seconds shouldn’t be problematic.
Screenshot_2015-07-28_07-52-16

Next you can set a variable with the number of seconds your system has been idle.

Screenshot_2015-07-28_07-50-27

After you have that in place it’s up to you to get creative with it. Here I’m illustrating a basic framework for acting on the idle state. I’ve minimized the actions that go beyond the scope of this blog post, to avoid confusion.

I’ve implemented a variable to track whether we are already idle or not (based on what happened the last time the macro executed automatically). This lets us only execute our “idle” actions one time until we’re active again, and lets us execute our “okay, I’m back” actions just once after returning from idle.

Please read the notes in the macro names for a summary of what each action does.

img20150728080429

One Comment

Leave a Reply to confluencepoint Cancel reply

Your email address will not be published.