Displaying results of shell script

This subject came up a couple years ago but after searching more I don't see where it may have been resolved.

I'd like to execute a shell script and capture its output for display in the HUD overlay.

I can create a StreamDeck button that shows the HUD and I know how to embed variables into the displayed text by wrapping them in braces. What I'm missing is, how do I assign the output of the shell script to a variable BTT can access?

It still works like described in the post you linked using the "Run Real Java Script" action. Here a full example:

(async () => {

let shellScript = 'date';

let shellScriptWrapper = {
    script: shellScript, 
	launchPath: '/bin/bash',
    parameters: '-c', 
	environmentVariables: ''

};
let result = await runShellScript(shellScriptWrapper);

let hudAction = {
  "BTTActionHUDTitle": "Test",
  "BTTActionHUDDetail": result, // the result of your shell script
  "BTTActionHUDDuration": 3
}

let hudActionWrapper = {
  "BTTPredefinedActionType" : 254,
  "BTTHUDActionConfiguration":  JSON.stringify(hudAction)
  
}

 await callBTT('trigger_action', {json: JSON.stringify(hudActionWrapper)});



returnToBTT(result);

})();

However having the option to assign the result automatically to a variable is a good idea. I'll add that :slight_smile:

That would be awesome!

Thanks for the quick reply, @Andreas_Hegenberg.

In the latest alpha (3.9996) the result will be saved in the variable BTTLastTerminalCommandResult. I'll make that configurable in the future.

Depending on the action you use to execute the command / shell script, the execution will be async and BTT will not wait before it executes the show hud action. Thus you might need to add the "async delay" action .

Yep, that works perfectly, @Andreas_Hegenberg!

Interestingly, though, my existing Javascript solution using callBTT('set_string_variable... doesn't work under 3.9997. The variable no longer gets set. Just FYI.

that's weird, I can't think of a change that would make that not work.

It still seems to work fine here with a script like this:

(async () => {

let shellScript = 'date';

let shellScriptWrapper = {
    script: shellScript, 
	launchPath: '/bin/bash',
    parameters: '-c', 
	environmentVariables: ''

};
let result = await runShellScript(shellScriptWrapper);
await callBTT('set_string_variable', {variable_name: 'somevariablename', to: result});

returnToBTT(result);

})();

No, you're right. Sorry to have wasted your time. I must've mucked something up. Both approaches are working now.

-- Robert

1 Like