How can I reference the Button Label in the Command Editor

Is it possible to reference a button's label in the Command Editor?
I want to pass the button's label value to my custom program that am calling from inside the Command Editor script (Standard Function (Opus or external)).

Additional Info
Continuing the discussion from Get/set Labels/Status via a script?:

The linked post was about file/folder labels, not button labels/names.

I don't think there is a way to refer to the button label from within its command. You can change set label via @label or by using Evaluator code in the main label field, but can't inspect it to find out what it currently is and run different things depending on that.

1 Like

Define the string via @evalalways. Use it with @label and eval code.

Can you clarify what I am doing wrong? The variable name shows instead of its value.

@evalalways:labelValue = @label
@async "C:\Program Files\AutoHotkey\AutoHotkey.exe" E:\Users\GaryR\Cloud\OneDrive\Documents\AutoHotKey\Projects\WinSetStyle\WinSetStyle.ahk "Toggle" ", MVRXX" labelValue

Try

@evalalways:labelValue="The Label String"
@label:labelValue
@async "C:\Program Files\AutoHotkey\AutoHotkey.exe" E:\Users\GaryR\Cloud\OneDrive\Documents\AutoHotKey\Projects\WinSetStyle\WinSetStyle.ahk "Toggle" ", MVRXX" {=labelValue=}
1 Like

Thank you but this changes the value of the button label.
What I actually need to do is retrieve and pass along the current label value without changing it.

@label is only for setting, not for reading the label. As Leo said, it seems there's currently no way of achieving that. :frowning_face:

1 Like

You only need to replace The Label String with the current label by copying and pasting.

In case it helps: By accident I just found this

The original label is available as the original_label variable.

in https://docs.dopus.com/doku.php?id=evaluator:applicable_contexts:functions:labels. Didn't try it...

Thank you, but original_label appears to work only when used with @label.

@label = original_label + "foo"

I need to use the value of original_label elsewhere in my script.

It seems that you don't actually need to use original_label in the @label statement, but the statement has to be present:

@eval:Output("original: " + original_label);
@label:="hello";

works fine and you can use the original for whatever - but that means you need to change the label to something.
You could do

@eval:Output("original: " + original_label);
@label:=original_label;

which leaves the label unchanged.

But I realized something else: You only get the original label (ie. the one set in the button editor), not the current value. So if it has been changed before, this won't help at all...

Perhaps it might be a nice addition to get current_label as a variable as well.

Of course, a solution might be to additionally track whatever you are setting as the label in a global variable...

Thanks, but even with your example, using original_label as an command argument later in the script does not work because the variable name is passed instead of its value.
Can you possibly show an example where the value for the original_label can be passed as an argument to another non-Dopus (Autohotkey, Powershell) script?

:frowning_face: No, it seems that I can't ...
I played around a bit more and perhaps now I understand fully what I didn't want to accept.

The original_label is only available for the refresh event, not the click event.
Therefore, even if you assign it to a variable in the @evalalways statement - which is evaluated for both events - that variable will be set for the refresh but fail for the click, so it can't be used further down...

Sorry, I'm out of ideas; I'd try something with a global variable as a workaround.
Good luck! :smiley:

What's the actual aim? There might be a better way to do it.

For example, if you only want to define a string once and have it in both the label and the command itself, you can do that by defining a variable in the button and using that in the command and setting the label to it. No need to read the label back in that case.

@Leo Thank you. I think your suggestion this is similar Ixp's recommendation.

The aim is to use the existing button(s) label's original_label value as an input argument to an Autohotkey (or other non-dopus) script.

Assigning a value to a variable and then using the variable to both set the label's value and use the variable, later in the script, does work. But with few hundred already defined button labels, setting a variable to it's unique label value inside every script is tedious.

Simply stated, having the ability to reference the original_label (or current_label) value, later in the script, would be the ideal solution. I realize you said earlier this was not possible. Perhaps in the future this could change?

@grosner sorry, I still don't quite understand this. Correct me if I'm wrong, but unless these buttons have been created in some dynamic way, you had to place the labels manually, right? So its value is constant. Also, to include the new code, you would still have to go through the trouble of manually editing each of the buttons...where you could manually set the same value that you manually set as the label value.
Out of curiosity and if is not too much trouble to you, could you give an example of real use where it is possible to contemplate this scenario in action?

2 Likes

@errante Here you go:

Scenario:
Like so many other features, the ability to add custom buttons to Dopus toolbars is extraordinary!

In my case, I have a button menu containing over 100 uniquely labeled (named) buttons. These buttons are named something like: 02.02 Tickers, 02.03 Indices ... 06.00 Holdings 01 - 20, and so on, with each button calling the same Autohotkey script that accepts several arguments, including one argument, having the same value as the button label (e.g. "02.02 Tickers").

The fun starts when creating or redoing the names or sequences (periodically needed).

This takes several tedious steps:

  1. Open the command editor
  2. Update the button label's value
  3. Copy the new button label's value to the copy buffer
  4. Position the mouse cursor inside the function editor
  5. If required, select old (non-contiguous) text to be overwritten
  6. Paste the previously copied value.
  7. Check the new value for accuracy.
  8. Run the script to ensure correct value is passed along.
  9. Close the command editor

Repeat for each of 100+ buttons.

With an available function accessible variable like "original_label", I could edit the label value in one place (the Label field.) This could substantially reduce editing time.

I hope this explains my scenario.

Despite this thread's length, and the generosity of contributions, I feel the need is quite simple:

Reference a button label's **value** (its name), from inside a function (or user command), by using a variable that can be utilized elsewhere in the function, as an argument without having to use @label in the function.

PS: I realize that, alternatively, it is possible to edit the Dopus XML customizations file. That approach is a topic for a different discussion.

Thanks for the explanation. :

It seems like a task that can be accomplished as follows: a script that reads these labels (from a file?) that change periodically and, from there, generates a new XML DO toolbar file (or modifies an existing one, depending). That's it, programmatically building/editing a toolbar. It can be relatively simple to do, especially if the buttons are similar and only the labels/parameters change. And it would definitely save you the task of having to manually edit each button :smile:

2 Likes