Last active
June 8, 2017 02:51
-
-
Save metametadata/0097efa1a081ce6d7bb3 to your computer and use it in GitHub Desktop.
listen to clipboard in Clojure using core.async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;... | |
(:import java.awt.Toolkit) | |
(:import (java.awt.datatransfer DataFlavor)) | |
;... | |
(defn- printer | |
[in] | |
(go (while true (println (<! in))))) | |
(defn- clipboard-listener | |
[out-ch] | |
(go-loop [] | |
(<! (timeout 1000)) | |
(let [clipboard (.getSystemClipboard (Toolkit/getDefaultToolkit)) | |
contents (.getContents clipboard nil) | |
text? (.isDataFlavorSupported contents DataFlavor/stringFlavor)] | |
(if text? (>! out-ch (.getData clipboard DataFlavor/stringFlavor)))) | |
(recur))) | |
;... | |
(let [ch (chan)] | |
(printer ch) | |
(clipboard-listener ch)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment