It would be possible that BTT shows a menu item like "Open recently copied image with BTT Image Editor" when it detects that the clipboard content is a jpg/png/etc image?
I think that it would be pretty handy.
It would be possible that BTT shows a menu item like "Open recently copied image with BTT Image Editor" when it detects that the clipboard content is a jpg/png/etc image?
I think that it would be pretty handy.
here is a small menu item configuration that shows an image icon in the menubar if an image has been copied:
edit_clipboard_menu.bttpreset (2.1 KB)
I have a menubar item which shows the last item in the clipboard manager and if it is a picture it shows [PICTURE]. The below code is basically this:
and
[
{
"BTTLastUpdatedAt" : 1790834755.302527,
"BTTTriggerType" : 820,
"BTTTriggerTypeDescriptionReadOnly" : "Clipboard Manager Did Add / Copy Item",
"BTTTriggerTypeDescription" : "Update \"Menubar item: Clipboard\"",
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"BTTUUID" : "DC377716-B4E0-4D76-88B4-FDAED9C884FC",
"BTTNotesInsteadOfDescription" : 1,
"BTTOrder" : 14,
"BTTActionsToExecute" : [
{
"BTTLastUpdatedAt" : 1777376127.2128611,
"BTTTriggerParentUUID" : "DC377716-B4E0-4D76-88B4-FDAED9C884FC",
"BTTIsPureAction" : true,
"BTTUUID" : "7EE3CEB0-1D29-4BF8-AB16-B566065F9F5C",
"BTTPredefinedActionType" : 281,
"BTTPredefinedActionName" : "Run Real JavaScript",
"BTTAdditionalActionData" : {
"BTTScriptFunctionToCall" : "get_clipboard",
"BTTJavaScriptUseIsolatedContext" : false,
"BTTAppleScriptRunInBackground" : false,
"BTTScriptType" : 3,
"BTTScriptExternalPath" : "/Users/user/Documents/btt/scripts/clipboard_menubar_item.js",
"changedFile" : "3C3EE0EA-CC35-4332-96C2-A4606399B0F9",
"BTTActionJSRunInSeparateContext" : false,
"BTTScriptString" : "async function get_clipboard() {\n // First try plain text\n let textResult = await get_items_from_clipboard_manager({\n start: 0,\n numberOfItems: 1,\n format: \"public.utf8-plain-text\",\n asBase64: false\n });\n\n let parsedText = JSON.parse(textResult);\n let custom_menubar_clipboard_full = (parsedText.items.length > 0) ? parsedText.items[0].content : \"\";\n\n // If no text, check if it's an image\n if (!custom_menubar_clipboard_full) {\n let imageResult = await get_items_from_clipboard_manager({\n start: 0,\n numberOfItems: 1,\n format: \"public.png\", // could also try public.tiff, public.jpeg\n asBase64: true\n });\n\n let parsedImage = JSON.parse(imageResult);\n let imageClipboard = (parsedImage.items.length > 0) ? parsedImage.items[0].content : \"\";\n\n if (imageClipboard) {\n await set_string_variable({\n variableName: \"custom_menubar_clipboard\",\n to: \"[PICTURE]\"\n });\n return \"[PICTURE]\";\n }\n\n // nothing useful in clipboard\n return \"\";\n }\n\n // If it was text, take only the first line\n let custom_menubar_clipboard = String(custom_menubar_clipboard_full).split(/\\r?\\n/)[0];\n\n // Truncate to 18 chars + ellipsis if needed\n if (custom_menubar_clipboard.length > 18) {\n custom_menubar_clipboard = custom_menubar_clipboard.substring(0, 18) + \"...\";\n }\n\n await set_string_variable({\n variableName: \"custom_menubar_clipboard\",\n to: custom_menubar_clipboard\n });\n\n return custom_menubar_clipboard;\n}\n",
"BTTAppleScriptUsePath" : false,
"BTTScriptLocation" : 3
},
"BTTGenericActionConfig" : "async function get_clipboard() {\n // First try plain text\n let textResult = await get_items_from_clipboard_manager({\n start: 0,\n numberOfItems: 1,\n format: \"public.utf8-plain-text\",\n asBase64: false\n });\n\n let parsedText = JSON.parse(textResult);\n let custom_menubar_clipboard_full = (parsedText.items.length > 0) ? parsedText.items[0].content : \"\";\n\n // If no text, check if it's an image\n if (!custom_menubar_clipboard_full) {\n let imageResult = await get_items_from_clipboard_manager({\n start: 0,\n numberOfItems: 1,\n format: \"public.png\", // could also try public.tiff, public.jpeg\n asBase64: true\n });\n\n let parsedImage = JSON.parse(imageResult);\n let imageClipboard = (parsedImage.items.length > 0) ? parsedImage.items[0].content : \"\";\n\n if (imageClipboard) {\n await set_string_variable({\n variableName: \"custom_menubar_clipboard\",\n to: \"[PICTURE]\"\n });\n return \"[PICTURE]\";\n }\n\n // nothing useful in clipboard\n return \"\";\n }\n\n // If it was text, take only the first line\n let custom_menubar_clipboard = String(custom_menubar_clipboard_full).split(/\\r?\\n/)[0];\n\n // Truncate to 18 chars + ellipsis if needed\n if (custom_menubar_clipboard.length > 18) {\n custom_menubar_clipboard = custom_menubar_clipboard.substring(0, 18) + \"...\";\n }\n\n await set_string_variable({\n variableName: \"custom_menubar_clipboard\",\n to: custom_menubar_clipboard\n });\n\n return custom_menubar_clipboard;\n}\n",
"BTTOrder" : 1
},
{
"BTTLastUpdatedAt" : 1777376138.2284389,
"BTTTriggerParentUUID" : "DC377716-B4E0-4D76-88B4-FDAED9C884FC",
"BTTIsPureAction" : true,
"BTTUUID" : "07398C55-A0A9-4E4A-8CD1-F5D47A5E8EE2",
"BTTPredefinedActionType" : 281,
"BTTPredefinedActionName" : "Run Real JavaScript",
"BTTAdditionalActionData" : {
"BTTScriptFunctionToCall" : "update_custom_menubar",
"BTTJavaScriptUseIsolatedContext" : false,
"BTTAppleScriptRunInBackground" : false,
"BTTScriptType" : 3,
"BTTScriptExternalPath" : "/Users/user/Documents/btt/scripts/update_clipboard_menubar_item.js",
"changedFile" : "0D9991F1-ADA5-4E56-B048-5E12F1929E45",
"BTTActionJSRunInSeparateContext" : false,
"BTTScriptString" : "async function update_custom_menubar() {\n\n // uuid of the menubar item\n const UUID = \"99A0BCC0-5483-4765-A8CC-2C87342E3BF1\";\n const get_custom_menubar_clipboard = await get_string_variable({variable_name:\"custom_menubar_clipboard\"});\n\n let text = get_custom_menubar_clipboard ? get_custom_menubar_clipboard : \"??\";\n\n let icon = {\n \"uuid\": UUID,\n \"text\": text,\n // \"sf_symbol_name\": \"doc.on.clipboard.fill\"\n }\n\n let result = await update_menubar_item(icon);\n\n returnToBTT(result);\n}\n",
"BTTAppleScriptUsePath" : false,
"BTTScriptLocation" : 3
},
"BTTGenericActionConfig" : "async function update_custom_menubar() {\n\n // uuid of the menubar item\n const UUID = \"99A0BCC0-5483-4765-A8CC-2C87342E3BF1\";\n const get_custom_menubar_clipboard = await get_string_variable({variable_name:\"custom_menubar_clipboard\"});\n\n let text = get_custom_menubar_clipboard ? get_custom_menubar_clipboard : \"??\";\n\n let icon = {\n \"uuid\": UUID,\n \"text\": text,\n // \"sf_symbol_name\": \"doc.on.clipboard.fill\"\n }\n\n let result = await update_menubar_item(icon);\n\n returnToBTT(result);\n}\n",
"BTTOrder" : 2
}
],
"BTTGestureNotes" : "Update \"Menubar item: Clipboard\""
},
{
"BTTLastUpdatedAt" : 1790834755.3025141,
"BTTTriggerType" : 674,
"BTTTriggerTypeDescriptionReadOnly" : "Menubar Item: Clipboard",
"BTTTriggerTypeDescription" : "Clipboard",
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"BTTUUID" : "99A0BCC0-5483-4765-A8CC-2C87342E3BF1",
"BTTAdditionalConfiguration" : "",
"BTTOrder" : 35,
"BTTActionsToExecute" : [
{
"BTTLastUpdatedAt" : 1777355343.0648479,
"BTTTriggerParentUUID" : "99A0BCC0-5483-4765-A8CC-2C87342E3BF1",
"BTTIsPureAction" : true,
"BTTUUID" : "54058882-19B7-4B3F-AC8C-8B2952923AD2",
"BTTPredefinedActionType" : 203,
"BTTPredefinedActionName" : "Show or Hide Clipboard or Pasteboard History",
"BTTAdditionalActionData" : {
"BTTActionClipboardManagerAutoSaveName" : "54058882-19B7-4B3F-AC8C-8B2952923AD2"
},
"BTTOrder" : 1
}
],
"BTTGestureNotes" : "Clipboard",
"BTTTriggerConfig" : {
"BTTScriptType" : 3,
"BTTTouchBarButtonLineHeight" : 0,
"BTTTouchBarItemIconWidth" : 22,
"BTTTouchBarButtonTextAlignment" : 2,
"BTTTouchBarItemSFSymbolDefaultIcon" : "",
"BTTTouchBarButtonTopMargin" : 0,
"BTTTouchBarButtonFontSize" : 8,
"BTTTouchBarButtonColor" : "0.000000, 0.000000, 0.000000, 0.000000",
"BTTTouchBarAlternateBackgroundColor" : "0.000000, 0.000000, 0.000000, 0.000000",
"BTTTouchBarButtonMonoSpace" : 1,
"BTTTouchBarAppleScriptStringRunOnInit" : true,
"BTTTouchBarAppleScriptString" : "async function somefunctionname() {\n\nlet result = await get_clipboard_content({format: \"public.utf8-plain-text\" /*optional*/, asBase64: false});\n\nreturn result;\n\n}\n",
"BTTTouchBarScriptUpdateInterval" : 0,
"BTTTouchBarAppleScriptUsePath" : 0,
"BTTTouchBarOnlyShowIcon" : false,
"BTTTouchBarItemIconType" : 1,
"BTTTouchBarItemSFSymbolWeight" : 0,
"BTTTouchBarItemIconHeight" : 22,
"BTTTouchBarButtonBaselineOffset" : 0
}
}
]
Since I'm using a script from an external file I'm not sure how BTT will react if this path is not found, but the actual script is already in BTTScriptString.
But you can test and/or Andreas can say if this will cause any issues ![]()
Thanks for the preset @Andreas_Hegenberg
The icon of the menu opens the image editor when a image is in the clipboard, but it is always visible, is not hidden when the clipboard is not an image.
This is the code od the javascript:
async function isImageInClipboard() {
try {
const result = await get_items_from_clipboard_manager({start: 0, numberOfItems: 1});
const data = typeof result === "string" ? JSON.parse(result) : result;
const previewText = data?.items?.[0]?.meta?.previewText;
const isImage = typeof previewText === "string" && previewText.startsWith("Image:");
return JSON.stringify({hidden: !isImage});
} catch (e) {
return JSON.stringify({hidden: true});
}
}
The imported preset is just one trigger in automations, isn't it? Is this code correct or something is missing? Is it hiding in your system?
Can you try to disable & reenable it? I was having similar issue when I added the trigger until I disabled & reenabled it. I'll check whether I can find any issue there
Thanks for your help @xidiot
I like the approach of a menu item that is shown/hidden depending of the clipboard content like the one proposed by Andreas.
As I'm not good with javascript, I don't know how to edit your code for doing this. ![]()
I have tried to disable & disable it, and I have also restarted BTT. Nothing has fixed it.
I will try now to restart the computer now…
I think I found an issue with the preset importer, I'll upload a fixed build in a minute.
once 6.895 is online, try to import this:
edit_clipboard_menu2.bttpreset (2.2 KB)
I'm running 6.895. I imported the new preset you uploaded ("edit_clipboard_menu2").
I have disabled/enabled the preset. I have also restarted BTT.
But it is not working. It is worse than before.
There is no icon image in the status bar. I only have an empty room between volume and control center:

Clicking that empty room doesn't do nothing, whatever I copy a text or an image in the clipboard.
When I run the script from the trigger inside BTT (clicking the "Run Script" button) the result is always {"hidden":true}, it doesn't matter if I copy text or images in the clipboard:
I'm running 15.8.1 Sequoia. Iwonder if it can be due the macOS version…
that is possible, could you tell me what this script returns when run from BTT while you have a image copied? Ah, and are you using BTT's clipboard manager? (BTT only monitors the clipboard if the clipboard manager is on)
async function isImageInClipboard() {
const result = await get_items_from_clipboard_manager({start: 0, numberOfItems: 1});
return result;
}
Possibly there is one more image type the previous sscript is not checking
I have duplicated the imported trigger to use the new script you have posted now. The new trigger with this new script is showing always the icon in the menubar.
The script always returns the same result when I run it inside BTT, it doesn't matter if I copy a text or an image:
{
"items" : [
],
"latest" : "N\/A"
}
I have never used the clipboard manager of BTT before, so probably this was causing the issue. I'm sorry. I thought BTT was using the macOS clipboard, sorry for the confussion.
I have activated the clipboard manager using an applescript that triggers a namedtrigger:
tell application "BetterTouchTool" to trigger_named "BTT_ClipboardManager_On"
This triggernamed has one action that is "Enable Clipboard Observation (Clipboard Manager)". Is this correct? Do I have to run this triggernamed everytime BTT restarts or BTT keeps it activated until it is disabled?
I have done the script test after activating clipboard manager (if I have activated correctly), so the result I have shown you is with the clipboard manager activated.
Currently only the actual clipboard manager actions (Show Clipboard Manager) will cause it to get enabled. The start / stop actions are just helper tools for managing specific clipboard manager behavior
Thanks for your help Andreas!!
Once I have shown the clipboard manager, the 2nd script is reading correctly the content of the clipboard.
And if I run the 1st script, the menu item is shown/hidden correctly depending of the content of the clipboard.
But when the statusbar icon is hidden, a blank space is shown.
This is the menubar when the clipboard content has an image:
![]()
This is the menubar when the clipboard content has not an image, showing a gap:
![]()
It would be possible to avoid the gap in the menubar when the clipboard content is not an image? I mean to see it like this:
![]()
Thanks!