Save a file directly to the clipboard on OS X

It's always funny what kind of crazy stuff is possible by just using bash and basic Unix tools.

Most websites hosting scientific publications offer citation information in BibTeX format. Unfortunately some of them think it would be extremely helpful to force you to download a single .bib file containing the requested citation data. Of course you can save the file, open it, select the contents, copy it and paste it into your desired bibliography file. But this is neither convenient nor efficient.

At first I tried to find a program that watches the contents of a folder on OS X. A post on StackOverflow suggested to take a look at the launchctl daemon. It's a nice program that can launch a script (or other program) when a file path has changed. Based on that I wrote a small bash script which reads the contents of a directory, copies the first file into the clipboard and deletes the file eventually. For an easy installation please follow the instructions I present on GitHub.

Now I can just save the file into this folder and the content is copied to the clipboard, ready to be pasted into my bibliography file.