Created
August 13, 2016 14:44
-
-
Save kindlychung/2e1e0c865285cc65c8aa5d1d253b2358 to your computer and use it in GitHub Desktop.
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.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