I want to add embedded command support for dynamic buttons in script commands, but AddButtonsData.embedded always returns an empty string. I don't know if I misunderstand how this property is used, and I haven't found any examples using this property.
I noticed this feature was added in stable version 13.16. I tried installing 13.16, but it still doesn't work. I don't know if I'm using it wrong, or if this feature has never worked correctly.
Here is a simple script that adds the MyCommand command, with the DYNAMIC parameter being the dynamic button parameter.
The output of embedded is an empty string.
With embedded commands, the script only needs to do simple parameter replacements when adding buttons, while the actual button commands are defined in the embedded commands.
In this way, if you need to modify the command a button runs, you only need to change the embedded command, without touching the script.
A simple example:
function OnAddCommands(addCmdData)
{
var cmd = addCmdData.AddCommand();
cmd.name = "MyCommand";
...
...
cmd.supportembedded = true; // <-------- set to true
}
function OnAddButtons(addButtonsData)
{
var embedded = addButtonsData.embedded;
var paths = [
"C:\\Users\\",
"C:\\Windows\\",
"D:\\"
];
for(var i = 0; i < 3; ++i) {
var button = addButtonsData.buttons.AddButton();
button.label = paths[i];
// Use regEx, as JScript does not have the replaceAll() method
button.func = embedded.replace(/\{\$1\}/g, paths[i]);
}
return true;
}
If my script needs to generate dynamic buttons from some paths obtained somewhere, I can just set button.func to the command defined in the embedded command and then replace the parameters, without hardcoding them into the script or passing complex commands through normal parameters.