Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Created August 13, 2016 14:44
Show Gist options
  • Save kindlychung/2e1e0c865285cc65c8aa5d1d253b2358 to your computer and use it in GitHub Desktop.
Save kindlychung/2e1e0c865285cc65c8aa5d1d253b2358 to your computer and use it in GitHub Desktop.
import java.io.FileWriter
object AppendClipboard extends App {
import sys.process._
val fw = new FileWriter("/tmp/clipboard.log")
def getClipContent(): String = {
val res = Process("pbpaste").lineStream.toList.mkString("\n")
res
}
def writeToLog(s: String) = {
fw.write(s)
fw.flush()
}
var content0 = getClipContent()
def watchClipboard(): Unit = {
while(true) {
Thread.sleep(100)
val content1 = getClipContent()
if(content1 != content0) {
writeToLog(content1 + "\n")
content0 = content1
}
}
}
try {
watchClipboard()
} finally {
fw.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment