Cut a line with ⌘X if no text selected like VSCode but how to check there are selected text or not?

I’d like to ⌘X cut behavior like VSCode on any apps.

  • if selected text, cut selected part
  • if no selection, cut current whole line

I make below but doesn't work cut whole line part. Seems "there are selected text or not" part doesn't make sense. Any suggestions? Thanks in advance!

[
  {
    "BTTLastUpdatedAt" : 1704666658.567965,
    "BTTTriggerType" : 0,
    "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
    "BTTPredefinedActionType" : 366,
    "BTTPredefinedActionName" : "Empty Placeholder",
    "BTTAdditionalConfiguration" : "1048584",
    "BTTKeyboardShortcutKeyboardType" : 0,
    "BTTUUID" : "D753B277-94D1-4C93-95C0-10AADC49E116",
    "BTTTriggerOnDown" : 1,
    "BTTLayoutIndependentChar" : "x",
    "BTTEnabled" : 1,
    "BTTEnabled2" : 1,
    "BTTShortcutKeyCode" : 7,
    "BTTShortcutModifierKeys" : 1048576,
    "BTTOrder" : 0,
    "BTTAutoAdaptToKeyboardLayout" : 0,
    "BTTAdditionalActions" : [
      {
        "BTTLastUpdatedAt" : 1704666213.004277,
        "BTTTriggerType" : -1,
        "BTTTriggerParentUUID" : "D753B277-94D1-4C93-95C0-10AADC49E116",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
        "BTTPredefinedActionType" : 256,
        "BTTPredefinedActionName" : "Save selected text to variable selected_text",
        "BTTKeyboardShortcutKeyboardType" : 0,
        "BTTUUID" : "9258735D-DD55-44B2-8189-B487819F4F39",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTShortcutKeyCode" : -1,
        "BTTShortcutModifierKeys" : -1,
        "BTTOrder" : 0,
        "BTTAutoAdaptToKeyboardLayout" : 0
      },
      {
        "BTTLastUpdatedAt" : 1704666213.0049081,
        "BTTTriggerType" : -1,
        "BTTTriggerParentUUID" : "D753B277-94D1-4C93-95C0-10AADC49E116",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
        "BTTPredefinedActionType" : 330,
        "BTTPredefinedActionName" : "If Condition",
        "BTTIfConditionFormat" : "selected_text == \"\"",
        "BTTIfConditionData" : "YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGvEBYLDBMYICorLTQ4PT5BRUlOT1JaXmJkVSRudWxs0w0ODxAREl8QF05TQ29tcG91bmRQcmVkaWNhdGVUeXBlXxAPTlNTdWJwcmVkaWNhdGVzViRjbGFzcxABgAKAFdIUDxUXWk5TLm9iamVjdHOhFoADgBTUDxkaGxwdHh9fEBFOU1JpZ2h0RXhwcmVzc2lvbl8QEE5TTGVmdEV4cHJlc3Npb25fEBNOU1ByZWRpY2F0ZU9wZXJhdG9ygBOADoAEgBHVISIjJA8lJicoKVlOU09wZXJhbmReTlNTZWxlY3Rvck5hbWVfEBBOU0V4cHJlc3Npb25UeXBlW05TQXJndW1lbnRzgAaABRADgAiADVx2YWx1ZUZvcktleTrSIw8QLIAH0i4vMDFaJGNsYXNzbmFtZVgkY2xhc3Nlc18QEE5TU2VsZkV4cHJlc3Npb26jMDIzXE5TRXhwcmVzc2lvblhOU09iamVjdNIUDzU3oTaACYAM0w8jOTo7PFlOU0tleVBhdGiACxAKgApdc2VsZWN0ZWRfdGV4dNIuLz9AXxAcTlNLZXlQYXRoU3BlY2lmaWVyRXhwcmVzc2lvbqM_MjPSLi9CQ15OU011dGFibGVBcnJheaNCRDNXTlNBcnJhedIuL0ZHXxATTlNLZXlQYXRoRXhwcmVzc2lvbqRGSDIzXxAUTlNGdW5jdGlvbkV4cHJlc3Npb27TSiMPS0xNXxAPTlNDb25zdGFudFZhbHVlgA8QAIAQUNIuL1BRXxAZTlNDb25zdGFudFZhbHVlRXhwcmVzc2lvbqNQMjPVD1NUVVZXTFhMWVpOU01vZGlmaWVyWE5TTmVnYXRlWU5TT3B0aW9uc15OU09wZXJhdG9yVHlwZYASCBAE0i4vW1xfEBtOU0VxdWFsaXR5UHJlZGljYXRlT3BlcmF0b3KjW10zXxATTlNQcmVkaWNhdGVPcGVyYXRvctIuL19gXxAVTlNDb21wYXJpc29uUHJlZGljYXRlo19hM1tOU1ByZWRpY2F0ZdIuL0RjokQz0i4vZWZfEBNOU0NvbXBvdW5kUHJlZGljYXRlo2VhMwAIABEAGgAkACkAMgA3AEkATABRAFMAbAByAHkAkwClAKwArgCwALIAtwDCAMQAxgDIANEA5QD4AQ4BEAESARQBFgEhASsBOgFNAVkBWwFdAV8BYQFjAXABdQF3AXwBhwGQAaMBpwG0Ab0BwgHEAcYByAHPAdkB2wHdAd8B7QHyAhECFQIaAikCLQI1AjoCUAJVAmwCcwKFAocCiQKLAowCkQKtArECvALHAtAC2gLpAusC7ALuAvMDEQMVAysDMANIA0wDWANdA2ADZQN7AAAAAAAAAgEAAAAAAAAAZwAAAAAAAAAAAAAAAAAAA38=",
        "BTTKeyboardShortcutKeyboardType" : 0,
        "BTTUUID" : "11284FA2-3C18-4C34-89EE-4E5D1028904A",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTShortcutKeyCode" : -1,
        "BTTShortcutModifierKeys" : -1,
        "BTTOrder" : 1,
        "BTTAutoAdaptToKeyboardLayout" : 0
      },
      {
        "BTTLastUpdatedAt" : 1704666213.0055761,
        "BTTTriggerType" : -1,
        "BTTTriggerParentUUID" : "D753B277-94D1-4C93-95C0-10AADC49E116",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
        "BTTShortcutToSend" : "55,123",
        "BTTKeyboardShortcutScope" : 0,
        "BTTKeyboardShortcutKeyboardType" : 0,
        "BTTUUID" : "F7CE4315-F875-4CEA-B1F1-E238C6E617D6",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTShortcutKeyCode" : -1,
        "BTTShortcutModifierKeys" : -1,
        "BTTOrder" : 6,
        "BTTAutoAdaptToKeyboardLayout" : 0,
        "BTTTriggerConfig" : {
          "BTTKeyboardPreventRecursiveTriggers" : 1
        }
      },
      {
        "BTTLastUpdatedAt" : 1704666213.0061998,
        "BTTTriggerType" : -1,
        "BTTTriggerParentUUID" : "D753B277-94D1-4C93-95C0-10AADC49E116",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
        "BTTShortcutToSend" : "56,55,124",
        "BTTKeyboardShortcutScope" : 0,
        "BTTKeyboardShortcutKeyboardType" : 0,
        "BTTUUID" : "B2C5DF06-3156-450E-A0E0-9576AD6E2F50",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTShortcutKeyCode" : -1,
        "BTTShortcutModifierKeys" : -1,
        "BTTOrder" : 7,
        "BTTAutoAdaptToKeyboardLayout" : 0,
        "BTTTriggerConfig" : {
          "BTTKeyboardPreventRecursiveTriggers" : 1
        }
      },
      {
        "BTTLastUpdatedAt" : 1704666213.00684,
        "BTTTriggerType" : -1,
        "BTTTriggerParentUUID" : "D753B277-94D1-4C93-95C0-10AADC49E116",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
        "BTTPredefinedActionType" : 334,
        "BTTPredefinedActionName" : "END If Condition",
        "BTTKeyboardShortcutKeyboardType" : 0,
        "BTTUUID" : "614556D2-8D85-4011-AFA3-7B9E65C64015",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTShortcutKeyCode" : -1,
        "BTTShortcutModifierKeys" : -1,
        "BTTOrder" : 8,
        "BTTAutoAdaptToKeyboardLayout" : 0
      },
      {
        "BTTLastUpdatedAt" : 1704666213.0073872,
        "BTTTriggerType" : -1,
        "BTTTriggerParentUUID" : "D753B277-94D1-4C93-95C0-10AADC49E116",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
        "BTTLayoutIndependentActionChar" : "x",
        "BTTShortcutToSend" : "55,7",
        "BTTKeyboardShortcutScope" : 0,
        "BTTKeyboardShortcutKeyboardType" : 0,
        "BTTUUID" : "8713B850-B2E6-4371-8A0D-07A4013EEE2A",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTShortcutKeyCode" : -1,
        "BTTShortcutModifierKeys" : -1,
        "BTTOrder" : 9,
        "BTTAutoAdaptToKeyboardLayout" : 0,
        "BTTTriggerConfig" : {
          "BTTKeyboardPreventRecursiveTriggers" : 1
        }
      }
    ]
  }
]

your logic is fine, the problem is - BTT doesn't really know whether text is selected or not. It just sends cmd+c to the system and then returns the clipboard contents.

Unfortunately when pressing cmd+c while nothing is selected, it will return the previous clipboard content.

I modified the behavior 4.369 alpha a bit, so it will try to figure out whether the clipboard content has changed and if not return an empty string. So maybe your shortcut will work correctly with that version.

Thanks for the quick response and the alpha version! It worked as intended!

Now I can not only cut, but also copy, capitalize, translate, and more, without tedious selection!