Skip to content

Instantly share code, notes, and snippets.

@danieldbower
Created May 31, 2012 18:31
Show Gist options
  • Save danieldbower/2845280 to your computer and use it in GitHub Desktop.
Save danieldbower/2845280 to your computer and use it in GitHub Desktop.
Working with the System Clipboard from Groovy
import java.awt.datatransfer.StringSelection
import java.awt.Toolkit
import java.awt.datatransfer.*
class ClipboardUtils{
static final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
static void setClipboardContents(final String contents){
clipboard.setContents(new StringSelection(contents), null)
}
static String getClipboardContents(){
return clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment