How to create a button that copies to the clipboard the value of a field

I want with this button to copy to the clipboard the value of a field of a choosen tiddler.

I’m beginning to think that it is more tricky than it seemed initially. (Unless i’m missing something big.)
I tried with the copy-to-clipboard Macro, but maybe there is something better?

Take a look at this post

1 Like

There are some interesting ideas here, fresh too. But for the moment I haven’t been able to get anything out of it (although maybe later I will succeed) Thanks for now

Here are two examples. The first uses the TWCore <<copy-to-clipboard>> macro. The second uses a $button widget with the tm-copy-to-clipboard message

\define copy(tid,field) <$macrocall $name="copy-to-clipboard" src={{{ [<__tid__>get<__field__>] }}}/>

\define copy2(tid,field)
<$button class="tc-btn-invisible">
   {{$:/core/images/copy-clipboard}}
   <$action-sendmessage $message="tm-copy-to-clipboard" $param={{{ [<__tid__>get<__field__>] }}}/>
</$button>
\end

<<copy "SomeTiddler" "somefield">>
<<copy2 "SomeTiddler" "somefield">>
1 Like

Thanks Eric. Btw, I know I have a lot to learn. This works, but to make this work for my particular case I would have to replace each “tid” with the name of the tiddler and each “field” with the name of my particular field, right?
But if I want to copy a field from the tiddler that contains this button how should I do it? (If for example I put this button in the ViewToolbar)

Create a tiddler (e.g., “CopySomeFieldFromCurrent”), tagged with $:/tags/ViewToolbar, containing:

\define copy(field)
<$button class="tc-btn-invisible">
   {{$:/core/images/copy-clipboard}}
   <$action-sendmessage $message="tm-copy-to-clipboard" $param={{{ [<currentTiddler>get<__field__>] }}}/>
</$button>
\end
<<copy somefield>>
2 Likes

That’s great, thank you for your time! :slightly_smiling_face: