set_clipboard_content not working?

Hey there!

I'm trying to store my clipboard into a variable, then copy another thing and after doing something with it, return my old string from the variable back to clipboard.

I successfully did the first two things, but can't seem to get the string from a variable back into the clipboard. I managed to do the same thing by calling Apple Script from BTT's JS, but the more concise option using BTT's Real JavaScript set_clipboard_content doesn't work.

I've tried this snippet from the documentation with no luck (doesn't even return 'success'), could anyone help me out?

(async ()=> {

let result = await set_clipboard_content({content:'<strong>Hello world</strong>', format: 'NSPasteboardTypeHTML'})
returnToBTT(result);
})();

Which version of BTT are you running? (This function was just recently added, and initially contained a bug - it should work with the latest versions (e.g. 4.306)

Welp, somehow BTT stopped showing me update notifications. I have just updated and am now on the latest 4.306.

However, the problem persists and maybe even worse. The code in my original post now returns TypeError: undefined is not an object, while this makes the BTT crash and quit completely:

(async ()=> {

let result = await set_clipboard_content("test");
returnToBTT(result);
})();

Ah sorry, you currently always need to pass a paste format. I'll change that to default to string.

await set_clipboard_content({content:'test', format: "NSPasteboardTypeString"})

Superb, now it works perfectly, thanks a lot!

Hmm, it seems that it doesn't work in each case after all. If I try to set the clipboard to the currently selected text, it doesn't go through. When I comment out the await set_clipboard_content line, it outputs 'success' just like it should. Any ideas?

(async ()=> {

let curr_clipboard = await callBTT('get_clipboard_content', {});

let result = await set_string_variable({variable_name: 'temp_clipboard', to: curr_clipboard});

let selectedText = await get_string_variable({variable_name:'selected_text'})

await set_clipboard_content({content:selectedText, format: "NSPasteboardTypeString"})


returnToBTT('success');

})();

Sorry, you are right. There was an issue with the callback handling. This should now be fixed in 4.307!

1 Like

Although it works now, the changes resulted in a new bug that makes BTT crash when I run my named trigger via Shortcuts app (it's fine if I do it using keyboard shortcut assigned via BTT).

Here's the macOS crash report.

My trigger is as follows:

  1. Save selected text to variable named selected_text
  2. Run Real Javascript:
(async ()=> {
let temp_clipboard = await callBTT('get_clipboard_content', {});

let result = await set_string_variable({variable_name: 'temp_clipboard', to: temp_clipboard});

let selectedText = await get_string_variable({variable_name:'selected_text'})

await set_clipboard_content({content:selectedText, format: "NSPasteboardTypeString"})
returnToBTT('success');
})();

  1. Send CMD OPT V to Arc
  2. Run Real Javascript
(async ()=> {
let temp_clipboard = await get_string_variable({variable_name:'temp_clipboard'})

await set_clipboard_content({content:temp_clipboard, format: "NSPasteboardTypeString"})
returnToBTT('success');
})();

I tested around a bit and it seems that this is the line that makes it crash:

let temp_clipboard = await get_string_variable({variable_name:'temp_clipboard'})

could you check with 4.310? Your action sequence was working fine here, but I think there might have a threading issue when it was called from the Shortcuts ap.

Unfortunately no, I'm on 4.315 and while it works via BTT, Shortcuts still throws me this error:

Screenshot 2023-11-03 at 13.10.58

I think I might have discovered the issue. Could you try again with 4.316?

1 Like

Nice, it works perfectly now!

1 Like