Skip to content

Instantly share code, notes, and snippets.

@torgeir
Forked from Folcon/clipboard-utils.clj
Last active March 1, 2017 07:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torgeir/109efcadd6b10c8ebea5b1e0a814c63b to your computer and use it in GitHub Desktop.
Save torgeir/109efcadd6b10c8ebea5b1e0a814c63b to your computer and use it in GitHub Desktop.
Just a quick clipboard slip/slurp I put together because I didn't find anything similar, don't know if it's useful for anyone but found it invaluable when getting large strings being returned from the repl and sticking the result in an editor for more car
(defn get-clipboard []
(.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit)))
(defn slurp-clipboard []
(if-let [contents (.getContents (get-clipboard) nil)]
(.getTransferData contents java.awt.datatransfer.DataFlavor/stringFlavor)))
(defn spit-clipboard [text]
(.setContents (get-clipboard) (java.awt.datatransfer.StringSelection. text) nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment