Send text to clipboard - Perspective

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()

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?

1 Like