How to change the Flow of a Macro already been triggered by Hot Key using a different one?

Hello Folks :wave:

Maybe some of you are aware of it - a lot of Hot Keys to remember and Complex Macros …

No I don’t want suggestions about Applications or Macros that are listing Hot Keys. My thing I want to implement is a Help System in my complex Macros using the same default Shift + Command + ? which every Mac user is aware of because it brings us all to an Application‘s Help Menu/Documentation/Book …

I‘ve already tweaked my Application‘s Help Menus using a global HotKey that acts differently based on the front Application but here is the thing … I want to use this Hot Key as a Trigger to bring up any Macro‘s only Help when the Macro is already running by ensuring that only the Help based Instance of the macro is running (killing the running Instance) and also blocking the Global Application Helper one.

Another thing to mention here is that my Global one already uses Semaphore Locking because it is based on multiple Tapping of the same Hot Key. So please consider this when making any suggestion.

I hope this wasn’t to long and complex - but it is all necessary information for you guys. Anything that doesn’t involve the full basis I’ve given you here will not work. Please keep this in mind.

Many thanks to who try’s to help me

Greetings from Germany :de:

Tobias

If I'm understanding correctly:

  • You have a global Help macro that is triggered with ⇧⌘?
  • You have multiple Macro Help macros (or "help" branches within your macros) that you also want to trigger with ⇧⌘?
  • If one of your "has Help" macros is running, ⇧⌘? should trigger that macro's Help and not the Global Help
  • If one of your "has Help" macros is running, that (those?) instance(s) should be killed when its Help is triggered

I think I'd do this from the Global Help macro. Test if any currently-executing instances are in a "has Help" list, if not then let Global continue as normal. If they are in your "has Help" list you can Cancel then (either "All Other Macros" or by iterating through %ExecutingInstances%, resolving/testing the macro names, and using "Cancel a Specific Macro" when appropriate), then "Execute a Macro" to run either the correct Help macro or the macro's "help branch" (by parameter).

The only tricky bit is running the right helper macro -- I don't believe you can "Use Variable" to run a macro, and "Execute a Macro" needs to be hard-coded. So I'd reach for AppleScript -- I won't embarrass myself by trying to tell you how to do that!

Hey Nige :wave:

First of all - a huge thank you :pray: for your reply …

Of course you’ve understood everything essential… and I like your idea. The AppleScript part is of course something I am able to solve … more tricky for me would be the Handling of the global Variable… we‘ll see if I will be able to get this working.

Before posting my attempt was to try it the other way around because it would be easier to supply the Macro‘s Name and UUID to the Global Macro using this information as Parameter. This way I maybe then don’t have to set up a dedicated global Variable. But then I had a slap my head moment reminding me off an issue - getting a conflict Palette !!

This is of course something that I don’t want …

Since I have more than one Macro with multiple branches accessible through multi tapping this way I would also not have to select the right Branches Help because I would also pass that via Parameter .. everything as JSON Array …

As I mentioned earlier in this reply I like your idea - even though I think about to eventually combine both our ideas if possible…

My Question here is:

Could a global HotKey be blocked any how by a Semaphore Lock based on a Global Variable if it has a Value ?!

Greetings from Germany :de:

Tobias

What global variable? You don't need one for this -- are you using it for something else?

I'm not sure I understand. You can't block a hot key. You could disable one or more of the macros that are triggered by it, or you could fire the macro and then exit without doing anything (either via semaphore or an "If" condition).

But I don't think that's necessary. Make it so that your Global Help macro is the only thing that is triggered by the hot key. Make the very first execution block of that macro be the "If" that decides whether to run one of the other help macros, cancel other instances, etc. The final "Else" would be "continue with the Global Help macro", and that's where you put your semaphore so that you only run one "Help" section of the Global Help macro at any one time.

So the Global Help always responds to the ⇧⌘? trigger, and then either

  1. Runs the appropriate macro's helper variant (along with cancelling executions etc) and exits
  2. Exits because the Global Help Routine is already running
  3. Executes the Global Help routine

You don't need to pass parameters except when triggering the macro helper variants (step 1) -- you should be able to make any decisions that are based on currently running macros by parsing the %ExecutingInstances%.

Hello Nige

Of course I need one since I have to store the Macros somehow permanently.

That will not be possible because my Global Helper Macro already uses Semaphore Locks to help detection of how many times I’ve pressed the HotKey.

Maybe could use something like that after the detection routines for the Hotkey Trigger. But not earlier. I’ll see what will work.

If you can remember the Hotkey Multipress Template from Dan - you’ll probably know what I am talking about - since my Global Helper Macro is based on that Template.

That’s what I am going to do … and this is the main reason I need the Global Variable for - so that I can compare the instances to the defined ones. To be sure I run the correct one‘s Help routine.

Thanks for now for your suggestions… I’ll see how it gets… if I get stuck I’ll come back to you for further help.

Thanks :pray:

Greetings from Germany :de:

Tobias

What I meant was you don't need a global variable because you can evaluate currently-executing macros at runtime. So when the Global Helper macro is triggered with ⇧⌘? it could compare the currently-executing macros against its own list of "has Help branch" macros and behave accordingly.

That list can be a local variable unless you want to be able to access it from "outside" the Global Helper macro -- perhaps for ease of editing, or to have macros automatically add themselves (via subroutine?) on first run. In that case I'd think about using a Dictionary instead.

You know your own macros best. But it seems from your description that:

when ⇧⌘? is pressed
if a macro-with-help is running then
   kill that instance
   launch that macro with the 'help' parameter
   exit 
else
   do multitap semaphore bit
   choose Global Help branch accordingly
end

That's to say -- you only need to consider multi-tap after you've decided that the Global Help macro should continue with global (rather than local) help.

This does depend on there only being one macro-with-help macro running at any time! There's no concept of "frontmost macro", so if there's two or more executing you won't know which the user is asking for help for.

Which does raise a question -- why are they asking for help? That implies an interruption of some kind, at which they have the need/opportunity to ask. That, in turn, implies a dialog of some sort. If that's the case -- could you make the help available from there? If you could you'd know the current macro, be able to pass parameters as required, and so on.

Hello Nige :wave:

Access from outside of the Macro is definitely the route I want to go for.

Thanks for the suggestion with the Dictionary… I’ll think about this - but I don’t know if I am going to do this…. We‘ll see ..

No because I want to have different options available based on the tab count of the HotKey Trigger. Therefore I will need to have that information at first. After that I am able to decide what to do and what not.

This will make it also far more easy to create a dynamic HTML Window.

Greetings from Germany :de:

Tobias

Then the spec is slightly different to your OP. But that shouldn't matter, you just reverse the order:

do multitap detection
switch(number of taps)
   case(1)
      if a macro-with-help is running then
         kill that instance
         launch that macro with the 'help' parameter
         exit
      else
         do normal 'taps = 1' thing
   break
   case(2)
      do 'taps = 2' thing
   break
   -- etc
end switch

Again, the real problem is what to do if more than one macro-with-help is running. Perhaps pop a pick-list so the user can choose which they want help with?

Hey Nige👋

I’ve mentioned this in the OP

Maybe you’re right about that I maybe should have written a little more about how my HotKey detection works and that everything should happen after.

Something like that was my intention to do. I’ll maybe build something dynamic based on how many Macros were selected with HTML.

I wanted to create HTML Windows anyway so the dynamic thing sounds even better - even though it is far more work I’ve to do.

Greetings from Germany :de:

Tobias

Not that bit.

That seems to mean that "any use of this hot key when a has-help macro is running should override the Global Help's multitap, and only the Global Help has multitap" -- but perhaps I'm reading too much into it.

Even so, you should be able to do the multitap detection and then act according to current context, as above.