Timeout based on macro use rather than system idle

I'm not sure that I'm following this, in fact I know I'm not.

I want to use a macro manually, repeatedly, and while I'm using it, over and over, I want another macro disabled. Then when I'm done with the first macro, I want to automatically reenable the other macro.

Right now, I have two ways to reenable the second macro:

  • A macro that specifically, manually, reenables it, that I use, manually, when I'm done using the first macro.
  • An idle trigger so that when the computer is idle for a minute, presumably longer than the time between repetitions of the first macro, I can assume that I'm done with the task and can then automatically renable the second macro.

To prevent reenabling the macro whenever the computer is idle, repeatedly, I have the reenabling macro disable itself when it's done.

But I would really rather not have it based on whether or not the whole computer is idle, rather just when the first macro hasn't been used for a minute or so.

Can Semaphores help with this?

The full context is that I have a macro that I want to be active most of the time, triggered whenever the Desktop Space changes (new trigger in v11, thanks!). But there are situations, like immediately after a reboot or other system-level issues, where things have not yet been set up properly, and the Space Has Changed macro gives erroneous results. Whle I'm setting up all the Desktops, I don't want the macro running, I want that to wait until I'm done using the setup functions.

Not by my Mac now, otherwise I’d create a demo macro, but it sounds to me like you could solve this simply by having a Set Macro Enable to disable your other macro at the start of your manually triggered macro, and set it to enable again at the end of the same macro

Edit: But reading you post again a bit more closely I see that you’d like a couple of minutes gap between your first macro finishing and the second macro being reenabled. A bit crudely I think I’d set this up as a third macro (executed at the end of the first) that would enabling the second macro after a two minute pause.
Edit2: But realized now that this second approach will not work ideally if the first macro is executed again while second macro is pausing, so I guess the first macro should also have something like a Cancel third macro-action in its beginning.

I'm thinking you could probably do something like:
Engine launch trigger > disable the desktop space switching trigger.
Check uptime. If uptime is greater than 5 minutes, re-enable the desktop space switching trigger.
Wait 5 minutes. Repeat above line. Done. :arrow_left: or chuck that into a loop that repeats each minute. You get the idea.

I've done this sort of thing quite frequently. But maybe my method isn't ideal.

What I do is have the first macro set a global variable to the current time. If the first macro has any loops, you need to set this global variable inside the loop. In other words, the first macro must be setting this global variable at least once every few seconds.

The second macro checks the value of the same global variable, and if the current time minus the saved time is under a minute, (or whatever value you define) the second macro stops.

I use semaphores a lot too, but there's no way for semaphores to solve this if the first macro is starting and stopping and restarting.

Thanks Alexander. This may be straightforward and simple enough to do it. I'm going to try this and see if it works as expected. Timing between instances of the first macro might be an issue, as the side affect that I'm trying to avoid takes a second or two to appear, but that may not matter.

No, I don't need the gap, I was thinking that I'd avoid having the second macro reenabled too soon by waiting until I was sure all use of the first macro was over for now.

Thanks Vincent. That kind of thing was my first thought, but it seemed too complex, like I wasn't approaching the problem with the right frame of mind. Might be useful elsewhere, though.

Thanks Airy. Like Vincent's suggestion, I'd been thinking along those lines too. I think Alexander may have the right of it, because I don't need to have the second macro continuously disabled, only disabled enough to prevent side effects of it being invoked as a result of the first macro, before everything is set up fully.

I've tested Alexander's suggestion and it works just fine. I'll mark it as the Solution.

I think there's an object lesson here -- there were two presumptions that I was making that prevented me from seeing the solution myself:

  • I was thinking in terms of disabling the second macro, the one triggered by the Space change, only when I was done with my manual process.
  • Because of the first assumption, I was then only thinking in terms of timers and having every use of the first macro reset the timer and when it stopped being reset, then it would expire and re-enable the second macro, which could now be triggered normally.

And, of course, I framed the question in such a way as to emphasize my presumptions, so that steered people's thinking in the same direction as I had already gone.

I think that pattern happens a lot here and in other help forums of all kinds.

Alexander's solution comes at the problem from the other end. In his method, the second macro is disabled only for the minimum time necessary to prevent it being triggered erroneously and problematically.

I put the Disable Macro command into the first macro right before the action that changes the Desktop Workspace (typing the ⌃→ hotkey) and re-enables it about 1.5 seconds later, after the system has had time to complete the Space change. That prevents the change from triggering the second macro, which would otherwise attempt to report the name of the new Space before it even has a name established.

1 Like

Here's another way of doing that:

Cancel specific macro MacroToCancel
Set MacroToCancel to %ExecutingInstance%
Disable second macro
Do stuff
Enable (or execute) second macro

I'm seriously not following this. Are you renaming the macro?

The second of these two actions logs the currently running macro identifier as a variable. So if you run the macro again, this specific previous instance will be cancelled by the first action.

This ensures that if you run it consecutively before the pause has ended, the previous instance, that would otherwise complete and enable (or execute) the second macro, is cancelled.

Therefore, only the final execution of the first macro will enable (or execute) the second macro.

This doesn't quite solve my issue, but it's a very interesting concept.

Then I must have misunderstood.

My suggestion allows you to trigger a macro over and over. Only when you're done triggering it, and a pause has successfully elapsed, will another macro be enabled or executed.

I thought that was what you were asking for.

This is exactly what my suggestion will do.

Thanks. Now I get it.

1 Like

That’s what I thought was required. I was overthinking it and making it more complicated than necessary.