Construct / Trigger a shortcut from variable?

Hi,

what I want to achieve when a streamdeck key was pressed:

If varX is set to 1: trigger CMD+1
If varX is set to 2: trigger CMD+2

etc…. Is it possible to generate the number in the CMD shortcut form a variable?

Thanks,

Simon

You can do this in Javascript.
See Using Java Script (not JXA) · GitBook

An example on that page:

asnyc function somefunctionname() {
let result = await trigger_named({trigger_name: 'Action5', wait_for_reply: true});
return result;
}

In your javascript, do something like this:

let varX = await get_string_variable({variable_name:'varX'});
let trigger_to_call = “Action” + varX;
await trigger_named({trigger_name: varX, wait_for_reply: true});

(note, untested code here, but this is the general idea)

Thanks a lot, but I have to ask again a question…

Where do I find then the correct function (instead of trigger_named) to send a shortcut to an application?

BR /

Simon

You can right-click any configured action in BTT and choose "Transform To Java Script" (sometimes you might want to edit the resulting JS a bit to remove not necessary properties)

Example: Trigger Cmd+1, Cmd+2, Cmd+3.... depending on the varX number

async function transformedActions() {

let varX = await get_number_variable("varX");
let keyCode = 18 + varX;

let result  = await trigger_action({json: JSON.stringify({
  BTTShortcutToSend: `55,${keyCode}`
}), wait_for_reply: true});


return true;
}

You can find a list of all the key codes here: Complete list of AppleScript key codes
1 - 0 are keycodes 18-29 on standard keyboard layouts, which is why I'm using 18+varX in the xample code

Thanks Andreas! That worked! :slight_smile: