I’m pleased to announce the first release of
open, a single-function library that allows one to open files in their default applications straight from OCaml:
$ opam install open $ ocaml > #require "open";; > Open.in_default_app "/path/to/my/favorite.pdf";; - : bool = true // pdf viewer opens and displays favorite.pdf > Open.in_default_app "/nonexistent/file.jpg";; - : bool = false // nothing happens > Open.in_default_app ".";; - : bool = true // file manager opens in current working directory
I found myself copying this code to many of my projects, so even though it’s just a few lines of OCaml I thought it may be useful to others as well. At a minimum, it will save me some copying in the future…
The library is hosted on Github and you can find more examples, details, and the API documentation there. Contributions are always welcome (e.g., I have not been able to test the library on a native Windows version of OCaml).