Time Police Macro - If App Active for X Minutes Then

Trying to make a macro that when a particular app is at the front for more than 15 minutes (Safari, Mail, RSS Reader, etc.) then an alert pops up that says something like "GET BACK TO WORK!". I am only part-way there, and I'm not sure it can be done without a script of some kind. What I have isn't quite right (see below) because it will run if the app is in the background for more than 15 minutes and then I happen to bring it back to the front at some random point, even for a moment. I want it to trigger only if the app has a window in focus for 15 minutes. Suggestions?

Here's the basic logic you need to use:

###Macro 1:
Trigger: One of those apps is activated.
Action: Use the action "Set Variable to Calculation" to save the current time. The value you should use is the function MILLISECONDS()

###Macro 2:
Trigger: One of those apps is deactivated.
Action: Clear the variable.

###Macro 3:
Trigger: Timer (up to you, but probably once a minute)
Action: If the variable isn't empty, calculate the elapsed time, and if it exceeds your threshold, display your prompt. To calculate the elapsed time, use an "IF" with a Calculation condition of MILLISECONDS() - VariableNameFromMacro1 > 15 * 60 * 1000. (i.e. 15 minutes in milliseconds).

###Consideration 1:

When Macro 3 displays the prompt, it will continue to do so every minute, until you switch apps, even if a prompt is being displayed. Which means if you walk away from your computer, you might end up with hundreds of prompts.

To prevent that, you can use a "Lock Semaphore" action at the start, like this:

Don't worry about how this works or what it does - just believe me when I say this will work. :slight_smile:

###Consideration 2:

You'll probably want to add an extra button to the "nag" prompt that acts like a snooze button. If you click it, reset the variable to the current time, i.e. MILLISECONDS().

1 Like

Thanks for the help! I've tried to follow as best I can as a noob. Wasn't sure if you meant to create 3 separate macros or to build them all into one, the way I did in the image below. (I fixed the variable names so that they match after the screenshot was taken.) Is this close?

No, they need to be 3 separate macros, because they have different triggers.

I’ll let you take another shot at it. Let’s see how close you come. :slight_smile: