Run an app for one hour macro example

Please give an example of a macro that would shut off an application in one hour.I don't want it to be a time trigger, but rather I want an amount of time to be a condition. That is, if one hour has passed, then quit the application.

Many thanks

Let me assume you want to trigger the macro with a hot key, let's say CMD-OPTION-S.

Let me assume that the name of the program you want to close is "Messages."

You said "I want the amount of time to be a condition." Oh, I guess then I have to rewrite the above. The above will work, so I'm not sure why you want to make it more complicated (and less CPU-efficient.) But here's a version with "a condition," as you requested:

Thanks so much! That gives me a much clearer idea how to work with time-related macros. KM is wonderful, but for those of us who are not programmers, it's not always clear how to set things up.

You are welcome. Thanks for being nice. One of the tricky things with helping people is that they usually are asking for a specific solution and about half the time that approach is not always the best. So it's tricky because if you tell them about a different solution they may get defensive.

1 Like

No, I'm always up for advice. I've been a supporter of KM since pretty much the beginning, but I am often confused on how to set up things which tokens and functions to use and so on. Not to impose on you too much, but could you point me in the direction of what commands to use if I wanted to display some kind of countdown display of the time elapsed either in the menu or on the screen as the Pause command counts?

Sure, I'll think about that. I have solved that myself a few times, in a few different ways. I can probably post one or two of my solutions below. This is still the same topic so it doesn't need a new post.

I usually use sound, not a display, to indicate a countdown. Sounds may not work for you, but it works for me, and it may work for some people, so I'll post an idea or two here:

The above code is something I use when I want to warn myself that if I don't stop the program it will start all over again. You may ask "where's the 30 second timeout?" It's actually in the cogwheel of the action, in the Set Action Timeout dialog box. Personally I wish these options were visible in the macro, but I think that the author of KM thought that they would be to rarely used to force it on everyone. But he already has an information for hiding rarely used information, those little triangles, so that's what I wish he would use for this feature. But I digress.

I have also used audible countdowns, something like this:

In the example above I have an audio countdown (which isn't always decrementing by one, but that hardly matters) and I allow the user to exit the loop by pressing the CTRL key.

Here's a really fun one that's visual instead of audible: (REALLY visual)

Again, it allows the user to cancel early with the CTRL key. It's actually hilarious. If you don't like it, I won't blame you. Make sure you use the "Large" option which is indicated above.

A slightly more respectable visual method might be this:

I think that's four methods. I've probably used other methods too, but that's a good start. I may add more later when I think of them.

Thanks, that's great!

Are the Group commands necessary or do they just indicate a subroutine? I'm not sure I understand what Group does.

Group just makes it easier for me to take an image snapshot. I'm lazy. It does nothing, functionally.

Thanks so much. I've really learned a lot. I now have a macro that turns off iTunes after an hour while displaying the minutes remaining.

Super. There are other ways to display information, like in the status bar at the top of macOS, but that's a lot of work for very little benefit. When I think of another way to display feedback, I'll add it here.

It's generally best not to have long running macros, even one that is just a Pause. So my solution to this would be a macro that triggers on launch and records the time, and another macro that triggers periodically while the app is running, and checks if the run time is long enough, and if so quits it. For example:

Macro One: Trigger on App Launch
Action: Set variable App Launch Time to calculation SECONDS()

Macro Two: Trigger on App Running repeating every N minutes (use N of 1-5 probably).

  • If calculation SECONDS() > App Launch Time + 60*60
    • Quit App

Thanks, Peter, I'll try that out.