Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a touch bar widget inside of a group #41

Closed
kimaldis opened this issue Nov 27, 2019 · 8 comments
Closed

Creating a touch bar widget inside of a group #41

kimaldis opened this issue Nov 27, 2019 · 8 comments
Labels
question Further information is requested

Comments

@kimaldis
Copy link

Checking out the example clock-widget.js, is it possible to create, say, a button widget inside of a group in the Touch Bar?

@Worie Worie added the question Further information is requested label Nov 27, 2019
@Worie
Copy link
Owner

Worie commented Nov 27, 2019

Do you need to create a button in the runtime by JS? What's the usecase?

Basically this library will do anything that BTT allows. And there's no action for creating widgets/button on the fly afair. Maybe there were some APIs for that but to be honest I'm not But you can create a button within a group and manage it later, yes.

There's add_new_trigger in BTT docs (link), but there's no add_new_button or add_new_widget. You can ask on https://folivora.ai/ directly whether it's possible to cover such case with intergrated webserver - if so, then this library will be able to do it as well, but not until it's enabled on BTT end.

Thanks for your interest in the library!

@kimaldis
Copy link
Author

I'm creating groups containing buttons with very similar actions. It would be a lot quicker to do this using a config array or file, creating buttons on the fly when BTT starts.

I came to your library from https://community.folivora.ai/t/dynamically-generated-widgets/2316 which seems to imply dynamically creating widgets is possible, then to the last few lines in clock-widget.js below. How am I misunderstanding this?

// you could also create a new widget on the fly, in the runtime!
const widgetPromise = btt.Widget.create({
...

@Worie
Copy link
Owner

Worie commented Nov 28, 2019

ah yes sorry. I'm not sure about placing them in groups though, I don't think this is the case I've handled. I'll look around and let you know, though don't expect a clean solution for now, more like a hacky-but-maybe-working one :)

@kimaldis
Copy link
Author

I'll make some enquiries with BTT.

@kimaldis
Copy link
Author

Grabbing the JSON for a group of buttons seems to contain button data. I may have been looking at this from the wrong end. I'll play some more, let you know what I find.

@Worie
Copy link
Owner

Worie commented Nov 28, 2019

You'd have to create a new group on the fly or update existing one. You can use btt.do method to do direct calls to BTT built in webserver.

For example:

btt.do('add_new_trigger',  `
  {
    "BTTTriggerType" : 630,
    "BTTTriggerTypeDescription" : "Group",
    "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
    "BTTPredefinedActionType" : -1,
    "BTTPredefinedActionName" : "No Action",
    "BTTEnabled2" : 1,
    "BTTUUID" : "3B4E8CE2-56CD-40CB-84F8-D552EAF716EF",
    "BTTNotesInsteadOfDescription" : 0,
    "BTTEnabled" : 1,
    "BTTModifierMode" : 0,
    "BTTOrder" : 33,
    "BTTDisplayOrder" : 0,
    "BTTMergeIntoTouchBarGroups" : 0,
    "BTTAdditionalActions" : [
      {
        "BTTTriggerType" : 639,
        "BTTTriggerTypeDescription" : "Apple Script Widget",
        "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
        "BTTPredefinedActionType" : -1,
        "BTTPredefinedActionName" : "No Action",
        "BTTEnabled2" : 1,
        "BTTUUID" : "14260C6B-E5FC-4EE4-BAC8-7D920819E333",
        "BTTNotesInsteadOfDescription" : 0,
        "BTTEnabled" : 1,
        "BTTModifierMode" : 0,
        "BTTOrder" : 0,
        "BTTDisplayOrder" : 0,
        "BTTMergeIntoTouchBarGroups" : 0,
        "BTTTriggerConfig" : {
          "BTTTouchBarButtonColor" : "75.323769, 75.323769, 75.323769, 255.000000",
          "BTTTouchBarItemIconWidth" : 22,
          "BTTTouchBarButtonTextAlignment" : 0,
          "BTTTouchBarItemPlacement" : 0,
          "BTTTouchBarButtonFontSize" : 15,
          "BTTTouchBarScriptUpdateInterval" : 5,
          "BTTTouchBarAlwaysShowButton" : false,
          "BTTTBWidgetWidth" : 400,
          "BTTTouchBarAppleScriptStringRunOnInit" : false,
          "BTTTouchBarAppleScriptString" : "return do shell script \"date\" #example: execute a shell script and use the result",
          "BTTTouchBarButtonWidth" : 100,
          "BTTTouchBarOnlyShowIcon" : false,
          "BTTTouchBarFreeSpaceAfterButton" : 5,
          "BTTTouchBarAppleScriptUsePath" : 0,
          "BTTTouchBarItemIconHeight" : 22,
          "BTTTouchBarItemPadding" : 0
        }
      },
      {
        "BTTWidgetName" : "No Name",
        "BTTTriggerType" : 642,
        "BTTTriggerTypeDescription" : "Shell Script \/ Task Widget",
        "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
        "BTTPredefinedActionType" : -1,
        "BTTPredefinedActionName" : "No Action",
        "BTTShellScriptWidgetGestureConfig" : "\/bin\/bash:::-c",
        "BTTEnabled2" : 1,
        "BTTUUID" : "F1E7B9E8-D32D-478B-8AA5-3CC24CA708B2",
        "BTTNotesInsteadOfDescription" : 0,
        "BTTEnabled" : 1,
        "BTTModifierMode" : 0,
        "BTTOrder" : 1,
        "BTTDisplayOrder" : 0,
        "BTTMergeIntoTouchBarGroups" : 0,
        "BTTTriggerConfig" : {
          "BTTTouchBarButtonColor" : "75.323769, 75.323769, 75.323769, 255.000000",
          "BTTTouchBarItemIconWidth" : 22,
          "BTTTouchBarButtonTextAlignment" : 0,
          "BTTTouchBarItemPlacement" : 0,
          "BTTTouchBarButtonFontSize" : 15,
          "BTTTouchBarShellScriptString" : "#example:\n{ echo \"Current Time: \" & date; }  | tr -d '\\n'",
          "BTTTouchBarScriptUpdateInterval" : 5,
          "BTTTouchBarAlwaysShowButton" : false,
          "BTTTBWidgetWidth" : 400,
          "BTTTouchBarAppleScriptStringRunOnInit" : false,
          "BTTTouchBarButtonWidth" : 100,
          "BTTTouchBarOnlyShowIcon" : false,
          "BTTTouchBarButtonName" : "No Name",
          "BTTTouchBarFreeSpaceAfterButton" : 5,
          "BTTTouchBarItemIconHeight" : 22,
          "BTTTouchBarItemPadding" : 0
        }
      },
      {
        "BTTWidgetName" : "No Name",
        "BTTTriggerType" : 642,
        "BTTTriggerTypeDescription" : "Shell Script \/ Task Widget",
        "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
        "BTTPredefinedActionType" : -1,
        "BTTPredefinedActionName" : "No Action",
        "BTTShellScriptWidgetGestureConfig" : "\/bin\/bash:::-c",
        "BTTEnabled2" : 1,
        "BTTAlternateModifierKeys" : 0,
        "BTTUUID" : "D62C7B04-8413-4BF9-BA2B-97E5D2255082",
        "BTTNotesInsteadOfDescription" : 0,
        "BTTEnabled" : 1,
        "BTTModifierMode" : 0,
        "BTTOrder" : 2,
        "BTTDisplayOrder" : 0,
        "BTTMergeIntoTouchBarGroups" : 0,
        "BTTTriggerConfig" : {
          "BTTTouchBarButtonColor" : "75.323769, 75.323769, 75.323769, 255.000000",
          "BTTTouchBarItemIconWidth" : 22,
          "BTTTouchBarButtonTextAlignment" : 0,
          "BTTTouchBarItemPlacement" : 0,
          "BTTTouchBarButtonFontSize" : 15,
          "BTTTouchBarShellScriptString" : "#example:\n{ echo \"Current Time: \" & date; }  | tr -d '\\n'",
          "BTTTouchBarScriptUpdateInterval" : 5,
          "BTTTouchBarAlwaysShowButton" : false,
          "BTTTBWidgetWidth" : 400,
          "BTTTouchBarAppleScriptStringRunOnInit" : false,
          "BTTTouchBarButtonWidth" : 100,
          "BTTTouchBarOnlyShowIcon" : false,
          "BTTTouchBarFreeSpaceAfterButton" : 5,
          "BTTTouchBarItemIconHeight" : 22,
          "BTTTouchBarItemPadding" : 0
        }
      }
    ],
    "BTTTriggerConfig" : {
      "BTTTouchBarButtonColor" : "75.323769, 75.323769, 75.323769, 255.000000",
      "BTTTouchBarItemIconWidth" : 22,
      "BTTTouchBarButtonTextAlignment" : 0,
      "BTTTouchBarItemPlacement" : 0,
      "BTTTouchBarButtonFontSize" : 15,
      "BTTTouchBarAlwaysShowButton" : false,
      "BTTTBWidgetWidth" : 400,
      "BTTTouchBarButtonWidth" : 100,
      "BTTTouchBarOnlyShowIcon" : false,
      "BTTTouchBarFreeSpaceAfterButton" : 5,
      "BTTTouchBarItemIconHeight" : 22,
      "BTTTouchBarItemPadding" : 0,
      "BTTKeepGroupOpenWhileSwitchingApps" : false
    }
  }
`);

Should theoretically create a new group with 3 buttons. Buttons are the array under BTTAdditionalActions key. So if you modify those, and rerun, you should get different results. Additionaly, there's also a native update_trigger action that allows you to modify existing triggers (in this case - a group).

It should work, may require a little bit of playing around with it but makes sense. I cannot test it though and won't be able to anytime soon :(

@kimaldis
Copy link
Author

Thanks. And no worries, you've been more than helpful.

@Worie
Copy link
Owner

Worie commented Nov 29, 2019

cool! closing for now, feel free to reopen / mention me if you find any obstacles

@Worie Worie closed this as completed Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants