Tutorial / New Feature: Text Selection Did Change Trigger

确实比较奇怪,我不确定是在哪一类app中有作用,哪一类中无作用

我测试了很多的应用,这跟应用有关,跟选择的文本时只读文本还是可编辑的编辑框还是html文档无关,但我没有总结出什么规律

就在我写这个反馈时,我不知道触发了什么,我在vivaldi中似乎又可以弹出菜单了


It is indeed rather strange. I am not sure in which types of apps it is effective and in which types it is not. I have tested many applications. This is related to the application and has nothing to do with whether the selected text is read-only text, an editable edit box, or an HTML document. However, I have not summed up any rules. Just when I was writing this feedback, I don't know what was triggered. In Vivaldi, it seems that I can pop up the menu again.

Hey, congrats on the baby and love this idea!! Thanks so much! It wasn't working at first in Chrome, but after a few minutes it did, and it's awesome! love the abilities!

Can the fade-in (show) speed be adjusted anywhere?

not yet, will be available in the ui soon. You can disable the effect in the menus visibility section

will wait for the UI option :+1:

So not sure if this is the right place for this, but is there anyway to use regex for the Trigger conditions? For example, I have case numbers that are always 8 digits and I want a certain menu to only appear when I select text that matches that pattern. I got it to work with a specific selected text string, but having it based on a pattern would help in a lot of cases!

1 Like

Nice work! And congrats to the baby!

Popclip is very underrated. When you start using it you cant live without it. Some nice ones i use are:

  • Opening addresses in apple maps
  • Adding trackingnumbers to parcel app
  • yt-dlp a highlighted url
  • open a highlighted terminal command directly in terminal. (very nice when following an install guide on a website)

As for now whats the limitations of your implemantion compared to popclip?

Would something like this yt-dlp popclip extension work by just changing the variable for selected text?

yt-dlp
--output "%(title)s.%(ext)s"
-f "bestvideo+bestaudio/best"
--no-part
--prefer-ffmpeg
--ffmpeg-location "/opt/homebrew/bin/ffmpeg"
--remux-video mp4
"$POPCLIP_TEXT"

I don't know very much about PopClip's capabilities but from a first quick look I don't think BTT has limitations compared to it. I'd think BTT's floating menus are much more flexible. However of course this feature is only 2 days old, so I'm sure there will be various edge cases that are already handled in PopClip that BTT does not yet. Please report anything you can find!

E.g. your command can be run using the "Run Shell Script" action, the variable would need to be replaced with {BTTTextSelection}

In general you can use all of BTT's scripting capabilities, easiest via the "Run Real Java Script action - that can also be generated best by ChatGPT, just point it to the docs: Using Java Script (not JXA) · GitBook and tell it the selected text is available via the BTTTextSelection variable

Maybe there are currently some limitations working with formatted text, modifying formatted text will be possible with one of the next BTT versions.

2 Likes

@wellwell for testing I tried some of the actions you described to the preset:
text-selection-menu8.bttpreset (131.2 KB)

  • your youtube download command (downloading to ~/Downloads). However currently you really need to select text that contains a full youtube link. Selecting formatted text with links is not yet possible. E.g. selecting this: willnotworkyet. I'll add an option to access the raw html source of a selection soon.
  • apple maps search
  • run selection in terminal

The preset now also shows how to hide e.g. the cut item if the current context doesn't allow cutting, or the paste item if the current context doesn't allow pasting.

5.088 should again fix some more things.

1 Like

Congratulations on your little one!

I'm really liking how well this is working so far!

I noticed that whenever I'm on YouTube and want to use yt-dlp, I have to click and drag over the url for the pop-up to work. Would it be possible to have the pop-up happen whenever cmd-L is typed or just "clicking" inside the url bar to select the full YouTube link? It's extra steps to click inside the url bar and then drag to select the whole thing.

Thanks again @Andreas_Hegenberg !

in safari the latest version 5.089 should allow clicking the address bar. Showing it via keyboard command (cmd+l) is also possible, I‘ll post an example tomorrow

2 Likes

Thanks! Awsome! Tried to change the yt-dlp to work all websites with chatgpt. But i just think it screwed it up. haha

function extractFirstLink(text) {
  // This regex will match:
  // 1) Optional protocol (http:// or https://)
  // 2) Optional "www."
  // 3) Any domain and optional trailing path/query
  const linkRegex = /(?:https?:\/\/|www\.)[^\s"'`<>]+/i;

  const match = text.match(linkRegex);
  if (!match) {
    return null;
  }

  let found = match[0];

  // If the matched URL doesn't start with protocol, prepend "https://"
  if (!/^https?:\/\//i.test(found)) {
    found = 'https://' + found;
  }

  return found;
}

async function downloadVideo() {
  let selectedText = await get_string_variable("BTTTextSelection");
  let link = extractFirstLink(selectedText);

  // If no valid link is found, exit early
  if (!link) {
    return null;
  }

  let shellScript = `/opt/homebrew/bin/yt-dlp \\
  --output "~/Downloads/%(title)s.%(ext)s" \\
  -f "bestvideo+bestaudio/best" \\
  --no-part \\
  --prefer-ffmpeg \\
  --ffmpeg-location "/opt/homebrew/bin/ffmpeg" \\
  --remux-video mp4 \\
  "${link}"`;

  let shellScriptWrapper = {
    script: shellScript
  };

  // Execute the shell script
  let result = await runShellScript(shellScriptWrapper);
  return shellScript;
}

function extractFirstLink(text) {
  // This regex will match:
  // 1) Optional protocol (http:// or https://)
  // 2) Optional "www."
  // 3) Any domain and optional trailing path/query
  const linkRegex = /(?:https?:\/\/|www\.)[^\s"'`<>]+/i;

  const match = text.match(linkRegex);
  if (!match) {
    return null;
  }

  let found = match[0];

  // If the matched URL doesn't start with protocol, prepend "https://"
  if (!/^https?:\/\//i.test(found)) {
    found = 'https://' + found;
  }

  return found;
}

async function itemScript(itemUUID) {
  let content = {
    BTTMenuItemVisibleWhileActive: 0,
    BTTMenuItemVisibleWhileInactive: 0
  };

  let selectedText = await get_string_variable("BTTTextSelection");

  if (extractFirstLink(selectedText) != null) {
    content = {
      BTTMenuItemVisibleWhileActive: 1,
      BTTMenuItemVisibleWhileInactive: 1
    };
  }

  return JSON.stringify(content);
}

刚刚我使用最新版本5.089,也使用了最新分享的预设,但是现在仍然在很多app中无法获取到弹窗,目前遇到的app有:office word/excel, obsidian

再次感谢您的付出,希望可以超越popclip,我觉得肯定会,加油
I just used the latest version 5.089 and also used the newly shared presets. However, I still cannot obtain pop-ups in many apps. The apps I currently encounter are: office word/excel, obsidian. Thanks again for your efforts. I hope it can surpass popclip. I think it will definitely happen. Come on!

@wellwell what do you mean by this?

我正在使用一个ai产品:豆包ai,它非常好用且强大,
I am using an AI product: Doubao AI. It is very useful and powerful.


我想使用子菜单,但是点击子菜单之后不知道如何返回主菜单,如何设置的何上图一样悬浮子菜单时展开而不覆盖主菜单的显示

I want to use the submenu. However, after clicking on the submenu, I don't know how to return to the main menu. How can I set it up so that when the submenu is hovered over, it expands without covering the display of the main menu, just like in the above picture?

Here is an example preset that shows how to do submenus. You can either use floating menu submenus, or you can assign the predefined action "Show Custom Context Menu (New)" to a menu item.

text-selection-menu10.bttpreset (197.7 KB)

This preset also shows a few things that are new in v5.090:

  • there is a new predefined action "Change Formatting Of Selected Text"
    • Can be used to change colors and sizes of selected text
  • there is a new predefined action "Run Text Selection Change Detection"
    • Can be used to show the menu even if you selected the text via keyboard. For example if you select text via shift + opt + arrow left/right, this preset defines a key sequences "double press option key" that will show the text selection menu when pressing opt twice. It also calls the menu when pressing cmd+L to select the addressbar.

Quick video:

1 Like

Noticed a bug while playing som chess in safari. Every time i moved a piece i heard the macos "bop" sound. Nothing activated in the recently used list. Checked with KeyCastr and noticed that if you click-drag the mouse and release in safari Better Touch Tools sends "cmd C".

Its only if you drag where there is no text, for ex if you play chess. It stops if I turn off the text selection menu preset.

Does anyone else get that?

that’s possible! Best disable the feature for that app for now, I‘m currently building a white/blacklist. I‘ll upload a fix for safari this evening

//edit I think I found a good general solution to that problem. Will be solved with the next alpha

1 Like

@wellwell could you check whether this is resolved with 5.093?

Yes! It seems to be gone know! Amazing!

Btw how many Better Touch Tools users are there? If thats not a company secret. :wink: Or around how many active licenses are there?
I couldnt use a computer without it. But it does take a long time to grasp all the functions.

1 Like