Tutorial / New Feature: Text Selection Did Change Trigger

Thank you. Andreas.
Can we optimize it to show the popup faster? pop clip almost instantly shows when you select a text.

Also in popclip there is an extension where you can append to clipboard, you can append once meaning copy text to an existing copy. is there away with this new feature to sppend more than twice?

Yes, I currently have a ~50-100ms delay for debugging stuff. I'll remove that for the final builds (//edit: removed in v5.124). The preset also has a 50ms show fade in animation, you can disable that if you want. It's in the "Visibility" section of the text-selection menu.

You mean just appending some text to the current clipboard?
Here is a simple JS that would do this:

async (clipboardContentString) => {
   let selectedText = await get_string_variable("BTTTextSelection");
   // this appends with a new line, if you don't need a new line remove the \n
   return clipboardContentString+"\n"+selectedText;
}

To add this as a ready to use item you can copy & paste this json into your menu:

[
  {
    "BTTActionCategory" : 0,
    "BTTLastUpdatedAt" : 1737929914.46645,
    "BTTTriggerType" : 773,
    "BTTTriggerTypeDescription" : "Standard Item",
    "BTTTriggerParentUUID" : "7B9EC08A-8B74-4613-A52C-2F00A7561951",
    "BTTTriggerClass" : "BTTTriggerTypeFloatingMenu",
    "BTTUUID" : "D0D40936-81AE-45D9-95DA-B59FE141B415",
    "BTTPredefinedActionType" : 366,
    "BTTPredefinedActionName" : "Empty Placeholder",
    "BTTAdditionalConfiguration" : "Menu Item: NSLocalizedString",
    "BTTEnabled" : 1,
    "BTTOrder" : 5,
    "BTTTriggerName" : "Menu Item: Append",
    "BTTMenuItemActions" : [
      {
        "BTTActionCategory" : 0,
        "BTTLastUpdatedAt" : 1737929879.330986,
        "BTTTriggerParentUUID" : "D0D40936-81AE-45D9-95DA-B59FE141B415",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeFloatingMenu",
        "BTTUUID" : "FEC5D16C-2398-4DED-B73C-8CD4141BBA6E",
        "BTTPredefinedActionType" : 448,
        "BTTPredefinedActionName" : "Transform Clipboard Contents with Java Script",
        "BTTAdditionalActionData" : {
          "SelectedTransformerTab" : 1,
          "BTTClipboardTransformerJS" : "async (clipboardContentString) => {\n   let selectedText = await get_string_variable(\"BTTTextSelection\");\n   return clipboardContentString+\"\\n\"+selectedText;\n}"
        },
        "BTTGenericActionConfig" : "AppendSelectedText",
        "BTTEnabled" : 1,
        "BTTOrder" : 52,
        "BTTMenuAvailability" : 0,
        "BTTMenuName" : "FEC5D16C-2398-4DED-B73C-8CD4141BBA6E"
      }
    ],
    "BTTMenuConfig" : {
      "BTTMenuItemBorderColorHoverDark" : "255.000000, 255.000000, 255.000000, 255.000000",
      "BTTMenuItemVisibleWhileActive" : 1,
      "BTTMenuItemIconType" : 2,
      "BTTMenuItemBackgroundTypeDark" : 4,
      "BTTMenuItemSFSymbolName" : "",
      "BTTMenuItemBackgroundColor" : "0.000000, 0.000000, 0.000000, 255.000000",
      "BTTMenuCategoryItemVisibility" : 0,
      "BTTMenuCategoryResizeOnHover" : 0,
      "BTTMenuItemBorderWidth" : 1,
      "BTTMenuCategoryOnlyShowIf" : 0,
      "BTTMenuCategoryModifiers" : 0,
      "BTTMenuItemBackgroundColorDark" : "108.442, 96.000, 190.435, 166.991",
      "BTTMenuScriptAlwaysRunOnFirstLoad" : 1,
      "BTTMenuItemMinHeight" : 30,
      "BTTMenuItemBackgroundColorHoverDark" : "90, 90.000, 180, 166.991",
      "BTTMenuCategoryShadow" : 0,
      "BTTMenuItemBorderColor" : "255.000000, 255.000000, 255.000000, 47.264978",
      "BTTMenuCategoryBackground" : 0,
      "BTTMenuCategoryZIndex" : 0,
      "BTTMenuCategoryItemBehavior" : 0,
      "BTTMenuItemSelectedTab" : 0,
      "BTTMenuHoverEndAnimationDuration" : 0.14999999999999999,
      "BTTMenuItemImageHeight" : 15,
      "BTTMenuCategoryItemSpacing" : 0,
      "BTTMenuItemScriptActive" : 1,
      "BTTMenuItemBlurredBackground" : 1,
      "BTTMenuItemIconPosition" : 0,
      "BTTMenuItemBackgroundType" : 4,
      "BTTMenuItemBorderColorDark" : "255.000000, 255.000000, 255.000000, 255.000000",
      "BTTMenuItemBackgroundColorHover" : "212.086655, 90.000000, 180.000000, 166.990997",
      "BTTMenuCategoryMenuVisibility" : 0,
      "BTTMenuScriptAlwaysRunOnAppear" : 1,
      "BTTMenuItemVisibleWhileInactive" : 1,
      "BTTMenuItemAnimateHover" : 1,
      "BTTMenuCategoryBorder" : 1,
      "BTTMenuItemMaxHeight" : 30,
      "BTTMenuAttributedText" : "{\\rtf1\\ansi\\ansicpg1252\\cocoartf2821\n\\cocoatextscaling0\\cocoaplatform0{\\fonttbl\\f0\\fnil\\fcharset0 HelveticaNeue;}\n{\\colortbl;\\red255\\green255\\blue255;\\red255\\green255\\blue255;}\n{\\*\\expandedcolortbl;;\\cssrgb\\c100000\\c100000\\c100000;}\n\\deftab720\n\\pard\\pardeftab720\\qc\\partightenfactor0\n\n\\f0\\fs44 \\cf2 \\expnd0\\expndtw0\\kerning0\nAppend}",
      "BTTMenuModifierMode" : 3,
      "BTTMenuHoverStartAnimationDuration" : 0.14999999999999999,
      "BTTMenuItemMinWidth" : 30,
      "BTTMenuItemMaxWidth" : 30,
      "BTTMenuTextMinimumScaleFactor" : 0.29999999999999999,
      "BTTMenuCategoryItemSizing" : 0,
      "BTTMenuAppearanceStyle" : 0,
      "BTTMenuItemBorderColorHover" : "255.000000, 255.000000, 255.000000, 170.952116",
      "BTTLastChangeUUID" : "FC0D0B65-D608-43DA-A803-4CBD103CB5D2",
      "BTTMenuCategorySpacing" : 0,
      "BTTMenuElementIdentifier" : "Append",
      "BTTMenuCategoryPosition" : 0,
      "BTTMenuItemIconColor1" : "255.000000, 255.000000, 255.000000, 255.000000",
      "BTTMenuAlwaysUseLightMode" : 1,
      "BTTMenuCategoryItemIcon" : 0,
      "BTTMenuCategorySize" : 0
    },
    "BTTMenuAvailability" : 0,
    "BTTMenuName" : "Append",
    "BTTGestureNotes" : "Standard Item"
  }
]
3 Likes
  1. In the dictionary application on Mac, the floating menu flashes and then disappears.

  2. When using submenus, after clicking the first submenu item and then clicking other menus, the first clicked submenu item will pop up.

Hello Andreas!

First off HUGE congratulations on the baby and another huge thank you for creating this. BTT has become an integral part of my life and I can't thank you enough.

I wanted ro report a strange behavior from this Trigger that has been going on since v5.085. As you can see in the video below, whenever this trigger is enabled, if double click on an empty search bar (whether in Safari, Chrome, Stickies, etc.) BTT will copy a blank to the clipboard. I turned off all triggers except the "Text Selection Did Change" automation, and whenever this is off the behavior stops, so I'm very sure this is the culprit. I also tried adding the "double-click" options as seen in the SS below, and attempted this with it enabled and disabled with no luck in fixing this. I've noticed this becoming a problem when I try to run the trigger on an item in clipboard or trying to paste an item only to realize there's a blank. Minor inconvenience but just wanted to point it out.

Additionally, the floating menu has completely stopped showing in the Safari link bar but still works in Chrome. I have to select the text then manually execute the trigger via key sequence. I've updated 3 times in the last couple days and these issues seem to persist.

Again, thank you for all your hard work, much appreciated :clap:



Thank you :slight_smile:

Some bugs fixed in v5.126

Also this preset slightly changes the position at which the menu appears, it now usually tries to center the menu above / below the mouse cursor.
text-selection-menu-v1.1.bttpreset.bttpreset (326.4 KB)

Just a little guide on how you can modify the positioning yourself:

Change Selection Menu Popup Position

Open the "Automations, Named & Other Triggers" section. There you'll find the "Text Selection Did Change" Trigger. This is the one that is responsible for recognizing that text has been selected and showing the menu.

When selecting that trigger you'll see that it contains multiple if conditions. These check the variable "BTTTextSelectionType" variable. This variable can have these values:

  • double-click
  • drag-left-up
  • drag-left-down
  • drag-right-up
  • drag-right-down

Now depending on the BTTTextSelectionType the predefined action "Update Floating Menu Properties" will be called. This action updates the positioning properties of the menu - before in the last step of the action sequence the menu is finally being shown.


3 Likes

Hi Andreas, great work!
Unfortunately the floating menu does not appear in BBedit, that's the software I most use for handling text.
Is there anything I can do to have it working?
I have noticed also that in LibreOffice the popup appears in a text document, but not when selecting text in a spreadsheet.
Thank you!

5.127 (uploading) adds support for BBEdit. LibreOffice might be hard though - I'll check.

1 Like

You are great! :pray:
BBedit is the most needed for me

tested BBedit, it works just fine, THANK YOU!

I did reactivate all items in the menu and it stoped freezing. I do keep the settings window open a lot when im in a frenzy of experimenting with new automations. hehe.

Would it be possible to make a timed auto close of the settings menu? Maybe that should be something built in to the app if it can cause problems?

I always use 3 finger click swipe down on the dock icons to close apps and Better touchtool closes down completly if i do that on the dock icon. Keyboard maestro for example only closes the settings window but does not terminate the app when using "quit command" on the dock icon.

Thank your all of this, but how can I retail a trigger when I update a preset? I created two triggers but when updated to V.1.1 my triggers are gone ): ughhh

There are various ways. I think best is to create a separate preset (a floating menu can contain stuff from various presets)

Unfortunately didn't have much time to work on it today, but the docs should go live sometime tomorrow and will discuss this. This menu is not really supposed to be used like is, it is more an example of what can easily be achieved.
Personally I have a separate menu where I just copied in the stuff I regularly need.

1 Like

Thank you will wait until tomorrow :slight_smile:

A really strange thing is happening
Now, every time a change a text selection (dragging), appears a Bettertouch Inspector web window (Better Touch Tool Javascript Runner)
This happens if Safari is opened
It depends on some debugging you set on while setting up things?
If I select by double click nothing happens, and also if Safari app is closed
strange...

That is if you have enabled this Safari option in the developer menu (you must have enabled that, it can not be done programatically)

You are right, sorry!

latest preset updated looks like we have double trigger?

Also, anyone know the YouTube engine URL? for a search trigger, Open URL/Open URL with selection.
URL below doesnt seem to work, even without the "s" or "%" https://www.youtube.com/results?search_query=%s

URL above gives me a "%s" on YouTube search

Quick update on this.

So it seems that the problem is that the "Text Selection Did Change" automation copies whatever content is "selected" in a given tab in safari. For example, if i have two tabs open (one with a page open with a word selected and one empty) and I click on the empty tab it will copy a blank to clipboard. Then, if i move BACK to the tab with the word selected it will also copy that word automatically to clipboards.

I created an apple script for command+V to paste the 2nd item in clipboard if the first is empty so I'm able to get around this but it's still persisting even if I set a condition prohibiting the automation/trigger from working in active_app=Safari. Additionally, this behavior happens even if safari is closed completely and will paste the blank into clipboard with the safari icon next to it.

Also, text select refuses to work in the ChatGPT desktop app no matter what i do if that can be added it would be HUGELY appreciated :pray:

currently on v5.132

@frankmak, which macOS version are you on? It seems to work good in my ChatGPT app and I haven't been able to reproduce the Safari issue either :-/ (macOS 15.3)