get_menu_item_value is returning an NSAppleEventDescriptor

Hi,

I’ve created a floating menu (Focus) that I want to use to input some text (in the item q1.) So far I have assigned this script to the Submit button:

async function getItemValue() {
   let itemVal = await get_menu_item_value( {'menu_name': 'Focus', 'item_name': 'q1'});
   return itemVal;
}

When I try running this in BTT it returns this value:

image

How can I access the string I’ve entered in the text field?

Hi @CalderH,

What happens if you run this?

async function getItemValue() {
   let itemVal = await callBTT(
      "get_menu_item_value", {
         'menu_name': 'Focus',
         'item_name': 'q1'
      }
   );
   return itemVal;
}

ah sorry that's a bug in the JS code. I'll fix it.

1 Like

Thanks both of you!
@fortred2 In case this comes up again, can you explain the difference in functionality between your code and mine? (Or are they supposed to be the same)

@CalderH I searched for posts in this community forum that contain the text get_menu_item_value and found a post from Andreas. There, you'll see Andreas uses...

await callBTT("get_menu_item_value", {

... instead of this, as you do in your script...

await get_menu_item_value( 

Your version of the script should work soon.

Unfortunately there's no mention of callBTT in the docs.

Got it, thank you! I had searched for that in the forums but I guess I didn’t scroll far enough.

callBTT was used in the past and is still used internally, but users can now directly use the shorter java script calls - the result should be the same. A version with the fix will be available in a few hours!

1 Like

Hi — continuing this thread because it may be a related issue, but let me know if it would be better to make a new thread. I now have this code for the submit button, to get the values of multiple inputs:

async function recordAnswers() {
	let itemNames = ['q1', 'q2', 'q3'];
	
    answers = {};

    for (let itemName of itemNames) {
        // Get the value of each input and add them to answers
        let itemVal = await callBTT(
            'get_menu_item_value', {
               menu_name: 'Focus',
               item_name: itemName
            }
        );
        answers[itemName] = itemVal;

        // Clear each input field
        await callBTT(
            'set_menu_item_value', {
                menu_name: 'Focus',
                item_name: itemName,
                value: ''
            }
        );
    };

    let answerString = JSON.stringify(answers);

    return answerString;
};

(Still using callBTT since I didn’t see the new version when I checked for updates — is there somewhere else I should look?)

This code is behaving erratically — sometimes it does work as expected: it returns a stringified object where the keys are the names of the fields and the values are my inputs, and it clears the input fields. However, usually what happens is it returns an object where the values are all empty strings — {q1: '', q2: '', q3: ''}, and the inputs aren’t cleared. If I change the call to set_menu_item_value so that it replaces the value with something other than an empty string, then that string appears instead in the output (like {q1: 'a', q2: 'a', q3: 'a'}, while the text in the menu itself does not change.

Am I doing something wrong? I worry I am still new to JS and misunderstanding how to use asynchronous functions.

did you try checking for updates manuall? It should show you v4.715 (https://folivora.ai/releases/btt4.715-2024092101.zip )