Copying a reporters result to the clipboard

I'm working on past Advent of Code puzzles to warm myself up for this year's and I wanted to copy a result to the clipboard so I could paste it into the AOC website.

But I can't see an easy way to do it

Am I missing something simple or is the facility missing?

I came up with this method

image

and then selecting the value in list block and using ctrl-C on it

but its a big sledgehammer for a little job :slight_smile:

you can use this block, but in order to copy a list, you need to do something like

[scratchblocks]
wait until(call (JSFunction [data] [let res = null; navigator.clipboard.writeText(data.toString()).then(_ => { res = data; ).catch(err => {throw err;}); return () => res;] :: operators) with inputs [what you need to copy]:: control
[/scratchblocks]

we can't see the whole code.

Not the same code, but this one would work: (takes a parameter data) const d = typeof data === 'string' ? data : JSON.stringify(data, null, 2); navigator.clipboard.writeText(d); note that running multiple times doesn't guarantee the first one is done before the second runs.

The problem is that navigator.clipboard.writeText is asynchronous, and you need to wait for the returned promise to resolve before doing the next action.

There is a handy tool to streamline the process: https://snap.berkeley.edu/snap/snap.html#present:Username=dardoro&ProjectName=userMenu.resultToClip&editMode

Just click reporter script with [Alt] pressed. For simple types, lists, and multidimensional tables clipboard will be filled with the text representation of the result.

I explicitly said that it's async, "running multiple times doesn't guarantee the first one is done before the second one runs"

The best solution would be js function blocks to be async/awaitable

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.