Random trigger generator

Hi, I do remote concierge work with BTT and I have created a trigger that will speak a pre-recorded message when I press a Touch Bar button. However, after a while of using the same message you can start to tell it's recorded if you are there enough. Is there a way using some sort of action or if anyone knows about javascript/AppleScript that I can set the key to randomly choose between a few different pre-recorded messages and play it, randomly selecting a new one each time I click the button. Any help would be greatly appreciated!

Here is a screenshot of the trigger I made (it's pretty simple)
image

What's happening here? Is it opening the .mp3 as a file, which that window appears in order to play it ?

If it's just simply a matter of having the computer speak some text, you can use AppleScript to invoke the text-to-speech synthesiser, which will say whatever is typed, and offer different voices, which can each be modulated by pitch, frequency, volume and speed.

say "What is it you can't face?" using "Kate"
delay 0.5
say "If you seek Amy." using "Daniel"
say "I'd love that." using "Amy"

You'll have to look up the various other options for manipulation of the waveform in the Scripting Additions dictionary, as I don't have a computer. I don't even know if "Amy" is a possible voice, but I like to think she'll be an Aussie.

So what mine does currently is it plays an audio file that I already created. So essentially it opens a file named "Greeting1" that plays in a media player and then it returns to the active screen I was working on (But that part isn't part of this, just it plays a file). What I'm trying to do is have it so that when I click the Touch Bar button, it randomly chooses one of the files in the folder, for simplicity lets call those Greeting1, Greeting2, and Greeting3, and then it plays that file. The part that I can't get is how to randomly select a file from the folder. I don't want it to do the same one every time and if it's random between a few different options than it sounds more realistic

I'd use the "Run Real Java Script" action and do something like this:

(async ()=> {


const randomNumberBetween1and5 = Math.floor(Math.random() * 6) + 1;
if(randomNumberBetween1and5 == 1) {
    await callBTT('trigger_named', {trigger_name: 'sound1'});
} else if(randomNumberBetween1and5 == 2) {
    await callBTT('trigger_named', {trigger_name: 'sound2'});
} else if(randomNumberBetween1and5 == 3) {
    await callBTT('trigger_named', {trigger_name: 'sound3'});
} else if(randomNumberBetween1and5 == 4) {
    await callBTT('trigger_named', {trigger_name: 'sound4'});
} else if(randomNumberBetween1and5 == 5) {
    await callBTT('trigger_named', {trigger_name: 'sound5'});
}

returnToBTT("");
})();

This triggers various named triggers depending on the random number. The named triggers can be configured in the "Name & Other Triggers" section in BTT and you can assign your mp3 actions to them.


This was perfect! Thank you sooooo much Andreas. That did it exactly as I wanted!

1 Like