How to put terminal commands within VS Code?

Hello Everyone, I was wondering how I can add terminal commands while I have VS Code open. For instance, I want to create a button on the touch bar that is called npm run dev, and once I click it I can run the command npm run dev in the terminal within VScode. How can I achieve this?

I'm not sure whether there is a good way to do this. Some chained commands would work, but that's obviously not nice. I don't think VSCode is currently scriptable?

Copy & paste this into the Touch Bar tab in BTT to get the action chain. The apple script copies the "npm run start" command to the clipboard

{
  "BTTTouchBarButtonName" : "npm run start",
  "BTTTriggerType" : 629,
  "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
  "BTTPredefinedActionType" : 124,
  "BTTPredefinedActionName" : "Trigger Menubar Menu-Item",
  "BTTMenubarPath" : "View;Command Palette...",
  "BTTEnabled2" : 1,
  "BTTEnabled" : 1,
  "BTTOrder" : 4,
  "BTTAdditionalActions" : [
    {
      "BTTTriggerType" : -1,
      "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
      "BTTPredefinedActionType" : 172,
      "BTTPredefinedActionName" : "Run Apple Script (blocking)",
      "BTTInlineAppleScript" : "set the clipboard to \"npm run start\"",
      "BTTEnabled2" : 1,
      "BTTEnabled" : 1,
      "BTTOrder" : 0
    },
    {
      "BTTTriggerType" : -1,
      "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
      "BTTPredefinedActionType" : 193,
      "BTTPredefinedActionName" : "Type Custom Text",
      "BTTStringToType" : "paste into active terminal",
      "BTTMoveCursorLeftBy" : "0",
      "BTTEnabled2" : 1,
      "BTTEnabled" : 1,
      "BTTOrder" : 1
    },
    {
      "BTTTriggerType" : -1,
      "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
      "BTTPredefinedActionType" : -1,
      "BTTPredefinedActionName" : "No Action",
      "BTTShortcutToSend" : "36",
      "BTTEnabled2" : 1,
      "BTTEnabled" : 1,
      "BTTOrder" : 2
    },
    {
      "BTTTriggerType" : -1,
      "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
      "BTTPredefinedActionType" : 129,
      "BTTPredefinedActionName" : "Delay Next Action",
      "BTTDelayNextActionBy" : "0.672096",
      "BTTEnabled2" : 1,
      "BTTEnabled" : 1,
      "BTTOrder" : 66
    },
    {
      "BTTTriggerType" : -1,
      "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
      "BTTPredefinedActionType" : -1,
      "BTTPredefinedActionName" : "No Action",
      "BTTShortcutToSend" : "36",
      "BTTEnabled2" : 1,
      "BTTEnabled" : 1,
      "BTTOrder" : 67
    }
  ]
}

This could probably be simplified by setting a shortcut to focus the terminal (https://stackoverflow.com/questions/42796887/switch-focus-between-editor-and-integrated-terminal-in-visual-studio-code ) or by using the "terminal launcher" extension

1 Like

This works :grin:, but I will look at your suggestion about simplifying it. Thank you!