Created
May 28, 2013 03:04
-
-
Save slyphon/5660281 to your computer and use it in GitHub Desktop.
This, more than anything, has improved my productivity an embarassing amount (w/ the scala repl)
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.{PrintWriter, OutputStreamWriter, BufferedOutputStream} | |
// copy given string to the mac clipboard by launching pbcopy in a subprocess | |
object Clipboard { | |
def pbcopy(string: String) { | |
val pb = new ProcessBuilder("/usr/bin/pbcopy") | |
val p = pb.start() | |
val stdin = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(p.getOutputStream))) | |
stdin.print(string) | |
stdin.close() | |
val exitStatus = p.waitFor() | |
if (exitStatus != 0) | |
throw new RuntimeException("pbcopy process exited with status" + exitStatus) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Here's a bit more concise version of that, too: