How can I send information to the clipboard from perspective?
I found this solution here on the forum:
from java.awt import Toolkit
from java.awt.datatransfer import StringSelection
def copy_clipboard(texto):
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
clipboard.setContents(StringSelection(texto),None)
It works in the script console, but when I call this function on an onActionPerformed from a perspective button, it doesn’t work. This error happens:
Has anyone here tried this?
Perspective scripts run in the gateway, not in the browser. You’ll need a custom component that can run real javascript, I suspect. Though I don’t know if browser security would let you do it anyways.
Well I will say that there are web pages that provide buttons that will copy text into the clipboard so I would say it is possible but as @pturmel said you have to make a custom component to do that.
Is there any documentation on creating a custom component?
Hey Victor, did you get anywhere with this in the end?
The java script side wouldnt be hard navigator.clipboard.writeText("sometext")
What are you trying to copy?
Me, I want to copy json for dev tools
hmm you should be able to print objects to the console.log with system.util.print()