Menu Bar Title Cannot Take Local / Instance Variables?

Hi @peternlewis,

Is it true that the menu bar title field cannot take local/instance variables?

If so, we will have to always delete the variable value after a macro completes (if we don't want to show anything when the macro is not running). This will cause an issue, as when the macro is aborted by other external means unexpectedly, there is no action to delete the variable value, and the menu bar will show the value at the time of the macro abortion. Supporting local/instance variables will solve the issue.

Maybe there are other solutions to the need (if we don't want to show anything when the macro is not running), but I can't think of one at the moment.

Thanks!

image

My take is that it can only take global variable because the macro group has no idea what macro is running (macro may have finished running and thus its local and instance variables are no longer exist). And there is possibility that other macros might use the same name as these are temporary variables that will be removed at end of macro execution, and thus will be hard to debug and error-prone if the feature support them.

"This will cause an issue, as when the macro is aborted by other external means unexpectedly,"
Those external means I assume will be macro will need to clear the global variable explicitly.

Is the menu always activated or manually activated by another macro ? If manually activated, can clear the global variable by that macro ?

2 Likes

Of course - the macro group would have no idea which macro instance was applicable.

Correct. Potentially you can use a Try or Catch action to catch the abort and clear the variable.

This is not practical. The local/instance variable is only available to the macro, and there could be multiple of them simultaneously.

2 Likes

@macdevign_mac, @peternlewis,

Thanks!

This seems a very promising action. I have not been able to make use of the action yet. It would be great if it can do something with it for my purpose.

What I'm trying to do is this:
An action sets a dynamic value (a countdown timer) to a variable which is used as part of the title to be displayed in the menu bar. This action uses a "While ... Until" action which could run for any amount of time.

I may choose to manually cancel the macro using "Cancel all macro" or "Cancel all other macro" etc.
I want to avoid adding a clear variable action whenever the "Cancel all macro" or "Cancel all other macro" is used (in case the above macro is running during the cancellation action).

What I want is, before the macro gets cancelled (in whatever way), the macro will jump out of the loop and execute the Set variable to %Delete% action.

Is it possible to accomplish through the "Try/Catch" action?

Here is my countdown timer macro (the main action is in Yellow color):

Countdown Timer - Menubar.kmmacros (13.8 KB)

🖼 Click to see screenshot

1 Like

If local/instance variables do not apply in this field. How about:

  1. Remove the local/instance variables from the dropdown list?
  2. Add some instructions to inform users of it?

They apply just fine - they just wont ever have any value since there is no instance to reference.

The instructions are already in the instructions pertaining to Local and Instance variables - they have no value outside a running macro.

They could be removed from the popup menu, but that would be an extremely specialised case that would need explicit coding for.

1 Like

Try/Catch will not help then, since those actions will cancel all the macros, and the Catch will not run.

2 Likes