Is it possible to programmatically create a new menu item in a Floating Menu?

Is it possible to programmatically create new menu items within a Floating Menu through scripting, rather than manually adding them in the GUI? I haven't found any method to do this in the documentation or the Community.

My current workaround is to manually create a large number of menu items and then use a Run JavaScript Action with a update_menu_item function to update each menu item's content/properties (triggered externally, e.g., via a Trigger On Script Output Change). For the unused items, I adjust the visibility by setting BTTMenuItemVisibleWhileActive and BTTMenuItemVisibleWhileInactive to 0.

Does this make sense as an approach? Or is there a more efficient way to dynamically add menu items?

Thanks in advance!

BTT: 4.673
MacOS: 14.6.1
Host: MacBook Pro (14-inch, 2021)

I'm currently working on an option that will allow a menu to retrieve its items dynamically via Apple Script / Shortcut / Java Script. This will make it much easier, but I'm still designing it.

Currently it would already be possible by calling update_trigger scripting function on the menu itself. For example this java script (run via the "Run Real Java Script" action) would set a menu's items (in this example the menu uuid is CF1116FE-F67D-4ADE-B2CB-508404F2155B )

Note: This will just replace any items for a given menu. If you want to add items, you will need to first retrieve them via get_trigger

async function someJavaScriptFunction() {
	let newItemDefinition =  {"BTTMenuItems" : [
      {
        "BTTActionCategory" : 0,
        "BTTLastUpdatedAt" : 1725529413.994216,
        "BTTTriggerType" : 773,
        "BTTTriggerTypeDescription" : "Standard Item",
        "BTTTriggerClass" : "BTTTriggerTypeFloatingMenu",
        "BTTEnabled" : 1,
        "BTTOrder" : 0,
        "BTTTriggerName" : "Menu Item: no-name-5B39A34",
        "BTTMenuConfig" : {
          "BTTMenuItemMaxHeight" : 50,
          "BTTMenuItemMinWidth" : 100,
          "BTTMenuAlwaysUseLightMode" : 1,
          "BTTMenuItemBackgroundColorDark" : "108.442, 96.000, 190.435, 166.991",
          "BTTMenuElementIdentifier" : "no-name-5B39A34",
          "BTTMenuItemBorderColorHover" : "255.000000, 255.000000, 255.000000, 255.000000",
          "BTTMenuItemVisibleWhileInactive" : 1,
          "BTTMenuCategoryBackground" : 1,
          "BTTMenuItemBackgroundTypeDark" : 4,
          "BTTMenuItemBackgroundType" : 4,
          "BTTMenuItemBackgroundColorHoverDark" : "90, 90.000, 180, 166.991",
          "BTTMenuItemBorderColorHoverDark" : "255.000000, 255.000000, 255.000000, 255.000000",
          "BTTMenuCategoryItemSizing" : 1,
          "BTTMenuItemBackgroundColor" : "108.442, 96.000, 190.435, 166.991",
          "BTTMenuItemBackgroundColorHover" : "90, 90.000, 180, 166.991",
          "BTTMenuItemMinHeight" : 50,
          "BTTMenuItemBorderColorDark" : "255.000000, 255.000000, 255.000000, 255.000000",
          "BTTMenuHoverEndAnimationDuration" : 0.14999999999999999,
          "BTTMenuItemBorderColor" : "255.000000, 255.000000, 255.000000, 255.000000",
          "BTTMenuAttributedText" : "<html><body  style=\"text-align:center;\"><span style=\"font-size:22px; text-align:center !important; color:white; font-family: -apple-system, BlinkMacSystemFont, sans-serif;\">New Item 1<\/span><\/body><\/html>",
          "BTTMenuHoverStartAnimationDuration" : 0.14999999999999999,
          "BTTMenuItemMaxWidth" : 200,
          "BTTMenuItemVisibleWhileActive" : 1,
          "BTTMenuItemIconColor1" : "255.000000, 255.000000, 255.000000, 255.000000"
        },
        "BTTMenuAvailability" : 0,
        "BTTMenuName" : "no-name-5B39A34",
        "BTTGestureNotes" : "Standard Item"
      },  {
        "BTTActionCategory" : 0,
        "BTTLastUpdatedAt" : 1725529413.994216,
        "BTTTriggerType" : 773,
        "BTTTriggerTypeDescription" : "Standard Item",
        "BTTTriggerClass" : "BTTTriggerTypeFloatingMenu",
        "BTTEnabled" : 1,
        "BTTOrder" : 0,
        "BTTTriggerName" : "Menu Item: no-name-5B39A34",
        "BTTMenuConfig" : {
          "BTTMenuItemMaxHeight" : 50,
          "BTTMenuItemMinWidth" : 100,
          "BTTMenuAlwaysUseLightMode" : 1,
          "BTTMenuItemBackgroundColorDark" : "108.442, 96.000, 190.435, 166.991",
          "BTTMenuElementIdentifier" : "no-name-5B39A34",
          "BTTMenuItemBorderColorHover" : "255.000000, 255.000000, 255.000000, 255.000000",
          "BTTMenuItemVisibleWhileInactive" : 1,
          "BTTMenuCategoryBackground" : 1,
          "BTTMenuItemBackgroundTypeDark" : 4,
          "BTTMenuItemBackgroundType" : 4,
          "BTTMenuItemBackgroundColorHoverDark" : "90, 90.000, 180, 166.991",
          "BTTMenuItemBorderColorHoverDark" : "255.000000, 255.000000, 255.000000, 255.000000",
          "BTTMenuCategoryItemSizing" : 1,
          "BTTMenuItemBackgroundColor" : "108.442, 96.000, 190.435, 166.991",
          "BTTMenuItemBackgroundColorHover" : "90, 90.000, 180, 166.991",
          "BTTMenuItemMinHeight" : 50,
          "BTTMenuItemBorderColorDark" : "255.000000, 255.000000, 255.000000, 255.000000",
          "BTTMenuHoverEndAnimationDuration" : 0.14999999999999999,
          "BTTMenuItemBorderColor" : "255.000000, 255.000000, 255.000000, 255.000000",
          "BTTMenuAttributedText" : "<html><body  style=\"text-align:center;\"><span style=\"font-size:22px; text-align:center !important; color:white; font-family: -apple-system, BlinkMacSystemFont, sans-serif;\">New Item 2<\/span><\/body><\/html>",
          "BTTMenuHoverStartAnimationDuration" : 0.14999999999999999,
          "BTTMenuItemMaxWidth" : 200,
          "BTTMenuItemVisibleWhileActive" : 1,
          "BTTMenuItemIconColor1" : "255.000000, 255.000000, 255.000000, 255.000000"
        },
        "BTTMenuAvailability" : 0,
        "BTTMenuName" : "no-name-5B39A34",
        "BTTGestureNotes" : "Standard Item"
      }
    ]};


   await update_trigger({"uuid": "CF1116FE-F67D-4ADE-B2CB-508404F2155B", "json": JSON.stringify(newItemDefinition)})
 return "done";
}

1 Like

That worked! Thank you Andreas :slight_smile: