Does anyone know if and how I can access (BTT)@clipboard(BTT) via JavaScript or maybe use the action "Assign/Set Value for Variable" to create another var (if there's not other option to access it directly).?
Thank you in advance.
Does anyone know if and how I can access (BTT)@clipboard(BTT) via JavaScript or maybe use the action "Assign/Set Value for Variable" to create another var (if there's not other option to access it directly).?
Thank you in advance.
get_clipboard_content
Thank you Andreas! So that var is executing the get_clipboard_content() ?
I'm trying to trigger an update to a menubar, using the following trigger - "Clipboard Contents Did Change", but this only works if I copy a new item. Is there a way "Clipboard Contents Did Change" to be triggered whenever I copy (e.g. "Copy & Move To Top") an existing item from CM?
This is currently not well supported because BTT intentionally ignores stuff copied from BTT to prevent some cases of infinite recursion.
So basically you want to trigger copy & move to top and additonally trigger some extra action?
End goal is to have a menubar item which is showing what's the first item in the CM, the one which will be pasted. At the moment I'm doing it like this:
Trigger:
[
{
"BTTLastUpdatedAt" : 1759265139.6290998,
"BTTTriggerType" : 783,
"BTTTriggerTypeDescriptionReadOnly" : "Clipboard Contents Did Change",
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"BTTUUID" : "DC377716-B4E0-4D76-88B4-FDAED9C884FC",
"BTTOrder" : 20,
"BTTActionsToExecute" : [
{
"BTTLastUpdatedAt" : 1759266924.2020769,
"BTTTriggerParentUUID" : "DC377716-B4E0-4D76-88B4-FDAED9C884FC",
"BTTIsPureAction" : true,
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"BTTUUID" : "7EE3CEB0-1D29-4BF8-AB16-B566065F9F5C",
"BTTPredefinedActionType" : 281,
"BTTPredefinedActionName" : "Run Real JavaScript",
"BTTAdditionalActionData" : {
"BTTScriptFunctionToCall" : "get_clipboard",
"BTTJavaScriptUseIsolatedContext" : false,
"BTTAppleScriptRunInBackground" : false,
"BTTScriptType" : 3,
"BTTAppleScriptString" : "async function get_clipboard() {\n let custom_menubar_clipboard_full= await get_clipboard_content({\n format: \"public.utf8-plain-text\",\n asBase64: false\n });\n\n if (!custom_menubar_clipboard_full) return \"\";\n\n \/\/ 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 and append 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({variableName: \"custom_menubar_clipboard\", to: custom_menubar_clipboard})\n return custom_menubar_clipboard;\n}\n",
"BTTScriptExternalPath" : "\/Users\/myuser\/Library\/CloudStorage\/OneDrive-\/Documents\/btt\/scripts\/clipboard_menubar_item.js",
"changedFile" : "BBE96148-F9F5-41DA-8B6C-B69805156C58",
"BTTActionJSRunInSeparateContext" : false,
"BTTAppleScriptUsePath" : false,
"BTTScriptLocation" : 3
},
"BTTRealJavaScriptString" : "async function get_clipboard() {\n let custom_menubar_clipboard_full= await get_clipboard_content({\n format: \"public.utf8-plain-text\",\n asBase64: false\n });\n\n if (!custom_menubar_clipboard_full) return \"\";\n\n \/\/ 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 and append 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({variableName: \"custom_menubar_clipboard\", to: custom_menubar_clipboard})\n return custom_menubar_clipboard;\n}\n",
"BTTOrder" : 1
},
{
"BTTLastUpdatedAt" : 1759266924.202096,
"BTTTriggerParentUUID" : "DC377716-B4E0-4D76-88B4-FDAED9C884FC",
"BTTIsPureAction" : true,
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"BTTUUID" : "07398C55-A0A9-4E4A-8CD1-F5D47A5E8EE2",
"BTTPredefinedActionType" : 281,
"BTTPredefinedActionName" : "Run Real JavaScript",
"BTTAdditionalActionData" : {
"BTTScriptFunctionToCall" : "update_custom_menubar",
"BTTJavaScriptUseIsolatedContext" : false,
"BTTAppleScriptRunInBackground" : false,
"BTTScriptType" : 3,
"BTTAppleScriptString" : "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\": \"laptopcomputer.and.arrow.down\"\n }\n\n let result = await update_menubar_item(icon);\n\n returnToBTT(result);\n}\n",
"BTTScriptExternalPath" : "\/Users\/myuser\/Library\/CloudStorage\/OneDrive-\/Documents\/btt\/scripts\/update_clipboard_menubar_item.js",
"changedFile" : "B66B5F39-129C-4FF4-A433-76EFB49149FD",
"BTTActionJSRunInSeparateContext" : false,
"BTTAppleScriptUsePath" : false,
"BTTScriptLocation" : 3
},
"BTTRealJavaScriptString" : "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\": \"laptopcomputer.and.arrow.down\"\n }\n\n let result = await update_menubar_item(icon);\n\n returnToBTT(result);\n}\n",
"BTTOrder" : 2
}
]
}
]
[
{
"BTTLastUpdatedAt" : 1759265440.156709,
"BTTTriggerType" : 674,
"BTTTriggerTypeDescriptionReadOnly" : "Menubar Item: Clipboard",
"BTTTriggerTypeDescription" : "Clipboard",
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"BTTUUID" : "99A0BCC0-5483-4765-A8CC-2C87342E3BF1",
"BTTAdditionalConfiguration" : "",
"BTTOrder" : 19,
"BTTActionsToExecute" : [
{
"BTTLastUpdatedAt" : 1759265211.398401,
"BTTTriggerParentUUID" : "99A0BCC0-5483-4765-A8CC-2C87342E3BF1",
"BTTIsPureAction" : true,
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"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
},
{
"BTTActionCategory" : 6,
"BTTLastUpdatedAt" : 1759265693.1184371,
"BTTTriggerParentUUID" : "99A0BCC0-5483-4765-A8CC-2C87342E3BF1",
"BTTIsPureAction" : true,
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"BTTUUID" : "852D8E1D-D724-40CA-A385-CC398ED1B36F",
"BTTPredefinedActionType" : 460,
"BTTPredefinedActionName" : "Hide Menu Bar Status Icons Left Of Specific Icon",
"BTTGenericActionConfig" : "com.hegenberg.BetterTouchTool (8AD53227-A7B6-414E-B898-5695AC298236)",
"BTTOrder" : 1
}
],
"BTTGestureNotes" : "Clipboard",
"BTTTriggerConfig" : {
"BTTTouchBarButtonColor" : "0.000000, 0.000000, 0.000000, 0.000000",
"BTTTouchBarAppleScriptStringRunOnInit" : true,
"BTTTouchBarItemSFSymbolWeight" : 0,
"BTTScriptType" : 3,
"BTTScriptFunctionToCall" : "somefunctionname",
"BTTTouchBarButtonMonoSpace" : 1,
"BTTTouchBarScriptUpdateInterval" : 0,
"BTTTouchBarButtonBaselineOffset" : 0,
"BTTTouchBarButtonLineHeight" : 0,
"BTTTouchBarItemSFSymbolDefaultIcon" : "",
"BTTTouchBarItemIconHeight" : 22,
"BTTTouchBarButtonTextAlignment" : 2,
"BTTTouchBarAlternateBackgroundColor" : "0.000000, 0.000000, 0.000000, 0.000000",
"BTTTouchBarAppleScriptUsePath" : 0,
"BTTTouchBarItemIconType" : 1,
"BTTTouchBarItemIconWidth" : 22,
"BTTTouchBarButtonTopMargin" : 0,
"BTTScriptLocation" : 0,
"BTTTouchBarButtonFontSize" : 8,
"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",
"BTTTouchBarOnlyShowIcon" : false
}
}
]
BTW is there a way to make get_clipboard_content() ignore when sensitive text is copied from KeePassXC (or similar apps), like CM is not showing the credentials copied from KeePassXC?
5.684 adds some scripting functions I had on my TODO list for quite some time:
For retrieving items: get_items_from_clipboard_manager
async function someJavaScriptFunction() {
//additional supported parameters: format, snippetGroup and asBase64
// if format is set to "all", it will return all stored information about the requested items, apart from "all" it supports any pasteboard UTI
return get_items_from_clipboard_manager({start: 0, numberOfItems: 10});
}
Example return value (a string, so to convert it to a JS object you'll need to call JSON.parse() on it:
{
"items" : [
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "5E19D142-CF3F-4C12-B9E2-324F8E7ED0CA",
"previewText" : "Test10",
"date" : "2025-10-01T13:25:14Z"
},
"content" : "Test10"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "B03EBB32-EFC5-4727-B3A9-9A5C6063DC7D",
"previewText" : "Test9",
"date" : "2025-10-01T13:25:12Z"
},
"content" : "Test9"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "30AACF7E-40A4-4153-BBFA-C68EEBC368B1",
"previewText" : "Test8",
"date" : "2025-10-01T13:25:12Z"
},
"content" : "Test8"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "A281F56D-2ECB-41D7-BF73-DC68804ED52F",
"previewText" : "Test7",
"date" : "2025-10-01T13:25:11Z"
},
"content" : "Test7"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "97217332-2184-4CB4-842E-D4137E63FBCD",
"previewText" : "Test6",
"date" : "2025-10-01T13:25:10Z"
},
"content" : "Test6"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "1B1F7F7D-EF28-4B45-9AF1-248768BFCB8C",
"previewText" : "Test5",
"date" : "2025-10-01T13:25:09Z"
},
"content" : "Test5"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "10C6C74F-8373-4810-909E-544318EC4ED7",
"previewText" : "Test4",
"date" : "2025-10-01T13:25:08Z"
},
"content" : "Test4"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "D8956BBC-7699-43D7-BF22-3E648B05D631",
"previewText" : "Test3",
"date" : "2025-10-01T13:25:08Z"
},
"content" : "Test3"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "A9880066-4438-4CD2-A103-FB7E3CAD47FC",
"previewText" : "Test2",
"date" : "2025-10-01T13:25:07Z"
},
"content" : "Test2"
},
{
"meta" : {
"copiedFrom" : "com.sublimetext.4",
"uuid" : "0BD5D9D6-B76D-4E91-99E9-5B59F9067C44",
"previewText" : "Test1",
"date" : "2025-10-01T13:25:07Z"
},
"content" : "Test1"
}
],
"latest" : "2025-10-01T13:25:14Z"
}
For pasting items: paste_clipboard_manager_items_with_uuids
async function someJavaScriptFunction() {
//additional supported parameters: deleteAfterPaste
return paste_clipboard_manager_items_with_uuids({uuids: "0BD5D9D6-B76D-4E91-99E9-5B59F9067C44,A9880066-4438-4CD2-A103-FB7E3CAD47FC"});
}
Also there is a new trigger in "Automations, Named & Other Triggers": Clipboard Manager Did Add / Copy Item"
Thank Andreas. Could you please clarify for me - if I use the new trigger " Clipboard Manager Did Add / Copy Item" should my previous code work or I should change the function to get_items_from_clipboard_manager() ?
it depends on what you need, yours will get whatever is currently in the system clipboard, the new clipboard manager function will give you what is in btts clipboard manager - these can differ for multiple reasons (e.g. duplicate handling, sensitive data handling, custom settings etc.)
Thank you. If I copy new item - trigger works, however it doesn't work if I do "Just Copy" or "Copy & Move To Top", is this expected?
I think for the just copy it makes sense to not trigger because it does not affect the clipboard manager, but copy & move to top I should make it so it triggers! I'll do that.