Tutorial / New Feature: Text Selection Did Change Trigger

Requires BTT 5.135

Documentation is available here:
https://docs.folivora.ai/docs/1009_text_selection_did_change.html

I have never used apps like Popclip in the past, however I'm currently in a situation where I have a baby occupying one of my arms most of the time, and realized it can be quite helpful to have some actions automatically pop up for my currently selected text.
So I thought about what would be necessary to make this possible with BTT, this lead to the new "Text Selection Did Change" trigger, which is available in the "Automations, Named & Other Triggers" section.

With this action you can e.g. pop up a floating menu once you have selected some text.

This is currently in early beta and doesn't handle many edge cases, but here is a example preset that should work with most apps:
https://folivora.ai/releases/text-selection-base.bttpresetzip

BTT makes these variables available upon text selection:

  • BTTTextSelection: The selected text
  • BTTTextSelectionElementRole: The role of the element in which text was selected (e.g. AXTextArea). This could be used to show different floating menus depending on the element.
  • BTTTextSelectionElementSubRole: : The sub-role of the element in which text was selected. This could be used to show different floating menus depending on the element.
  • BTTTextSelectionType gives the type of event that triggered the text selection. Currently can be:
    • double-click
    • drag-left-up
    • drag-left-down
    • drag-right-up
    • drag-right-down
  • BTTTextSelectionCuttable: Cut is available in current context
  • BTTTextSelectionEditable: Current selected text can be modified
  • List item

Nice. In my case, however, the menu does not appear in Chrome and Vivaldi. It works in Brave and Safari and in all my text apps.

I’ll add support for chrome based later today

2 Likes

Congratulations :tada: with the baby, and it's first gift to the BTT community :grinning:

@Frank1 so I just tried with vivaldi and chrome, but it seems to work fine here. You are still on macOS 14, right? Maybe I'll need to check with my macOS 14 machine next week.

感谢你的付出,期待这个功能很久了
Thank you for your efforts. I have been looking forward to this function for a long time.

Congratulations :tada: with the baby

  1. When I double-click to select text, the floating menu can be displayed for the first time. However, if I cancel the selection and double-click the same position again, it cannot be triggered to display. But when I double-click text at other positions, the floating menu can be popped up correctly. Note: I am in the idea ide.
  2. When I select text in Vivaldi, the floating menu is not popped up. I have also tested many applications. Some can and some cannot.

which version of macos are you on?

另外,我还发现一个问题,开启这个设置后会导致一些截图软件无法使用,因为需要拖动鼠标进行区域截图,我框选拖动完成后,松开鼠标截图就退出了。我退出btt后,截图操作可以恢复正常

In addition, I also found a problem. After turning on this setting, some screenshot software cannot be used, because you need to drag the mouse to take screenshots of the area. After the dragging is completed, I box, release the mouse to take screenshots and exit. After I quit btt, the screenshot operation can return to normal.

我只是进行按住鼠标左键进行截图框选,而不是进行文字选择,可能也触发了btt的一些事件,导致我不能正常截图
I just press and hold the left mouse button to select the screenshot box instead of the text selection, which may also trigger some events of btt, causing me to fail to take screenshots normally.

I‘ll check that! I wonder though what’s causing the vivaldi issue, vivaldi/chrome seem to work fine here.

13, Ventura :slight_smile: And I don't know why, but it works now. Did I do a BTT update? No idea anymore.

no, must be something that’s not always active, I‘ll try to figure it out

Okay :slightly_smiling_face: and one more detail. I don't know if you can change this, but if a window is at the edge of the screen, the menu of a selected word is opened “outside” the screen, so the menu is only partially visible.

ah yes you can enable this option on the floating menu. I'll update the example preset in the first post

1 Like

非常棒,可以解决屏幕边缘选择文本的问题!
Awesome, can solve the problem of selecting text at the edge of the screen。

@mahuaer, which screenshot app did you have problems with?


是中国的一个非常棒的截图软件叫PixPin,
今天我使用这个软件截图时提示:检测到其他程序按下了复制键。
2025年1月20日08:53:58,如截图所示的,我勾选“不再询问”,并选择“拒绝”,现在截图使用好像是正常的,但在昨天进行截图时,确实没有这个提示,也无法完成截图

此外,我在使用obsidian时,选择文本也不能弹出悬浮菜单

It is a very good screenshot software in China called [PixPin] (https://pixpin.cn),
When I took a screenshot using this software today, I prompted: It was detected that another program pressed the copy key.

At 08:53:58 on January 20, 2025, as shown in the screenshot, I checked "Don't ask anymore" and selected "Reject". Now it seems normal to use the screenshot, but when I took the screenshot yesterday, I really didn't have this prompt, and I couldn't complete the screenshot.

Also, when I use obsidian, selecting text doesn't pop up the floating menu either

我希望通过判断选择文本的类型弹出不同的悬浮菜单
比如如何在可以编辑文本框内选择文本,可以进行剪贴或者ai替换等操作。
在选择只读文本内容时不应该出现“剪切或者替换”等操作菜单
还有如何通过判断文本的内容,比如全是英文时,天出的菜单中展示翻译,
再比如根据当前的应用展示不同的悬浮菜单,例如:判断在指定软件比如代码编辑器中才需要“//注释”,
I hope to pop up different floating menus by judging the type of selected text. For example, when text is selected in an editable text box, operations such as cutting or AI replacement can be performed. When read-only text content is selected, operation menus such as "cut or replace" should not appear. Also, how can we judge the content of the text? For example, when it is all in English, translation is displayed in the popped-up menu. Another example is to display different floating menus according to the current application. For example, it is determined that "// comment" is only needed in a specified software such as a code editor.


刚刚突然弹出了获取这个权限的提示,我允许了这个选项后,重启btt,
再次回到vivaldi,现在我的选择文本触发悬浮菜单似乎已经可以正确出现。
可能就是因为这个权限的问题。那我不知道在其他一些应用中也是同样的问题,需要单独的授权才能弹出悬浮窗。
单这个弹出权限请求的面板不知道怎么触发,何时出现。所以如何这个权限时必须,系统优化触发的时机和检查提示,当没有正确触发时,让我明确知道我需要授权
Just now, a prompt for obtaining this permission suddenly popped up. After I allowed this option and restarted btt, and then returned to Vivaldi again. Now, it seems that the floating menu triggered by my selected text can appear correctly. Perhaps it is because of this permission issue. Then I don't know if it is the same problem in some other applications. A separate authorization is required to pop up the floating window. However, I don't know how to trigger and when the panel for this pop-up permission request will appear. So if this permission is necessary, the system should optimize the trigger timing and check prompts. When it is not triggered correctly, let me clearly know that I need authorization.