https://github.com/smolkaj/ocaml-open
Conveniently open files such as PDFs in their default applications.
https://github.com/smolkaj/ocaml-open
library ocaml
Last synced: 9 months ago
JSON representation
Conveniently open files such as PDFs in their default applications.
- Host: GitHub
- URL: https://github.com/smolkaj/ocaml-open
- Owner: smolkaj
- License: mit
- Created: 2017-11-17T21:43:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-05-21T04:57:22.000Z (about 1 year ago)
- Last Synced: 2025-10-05T11:48:44.135Z (9 months ago)
- Topics: library, ocaml
- Language: OCaml
- Homepage: https://smolkaj.github.io/ocaml-open/open/
- Size: 520 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# ocaml-open: open files in their default applications
[](https://github.com/smolkaj/ocaml-open/actions)
Conveniently open files such as PDFs in their default applications straigt from OCaml.
## Quick start
You can install the library using `opam`:
```
$ opam install open
```
Then in `utop` or `ocaml`,
```
$ ocaml
> #require "open";;
> Open.in_default_app "/home/steffen/ocaml.svg";;
- : bool = true
// SVG viewer opens and displays ocaml.svg
```

The boolean returned by `Open.in_default_app` indicates whether the open command exited normally:
```
> Open.in_default_app "/path/to/non-existent.file";;
- : bool = false
// nothing happens
```
Both absolute and relative paths are supported:
```
> Open.in_default_app ".";;
- : bool = true
// file manager displays current working directory
```
## API
The tiny API is documented [here](https://smolkaj.github.io/ocaml-open/).
## Building from source
### Dependencies
The library requires [`dune`](https://github.com/ocaml/dune) (formerly known as jbuilder) to build, but has no other dependencies.
### Building Library and Examples
Run `make` to build and `make test` to see the library in action. This should open several files from the `examples/basic` folder.
There is also a more sophisticated example in `examples/graphviz` that requires graphivz and Jane Street's [`core`](https://opensource.janestreet.com/core/) (version v0.9.0 or higher). You can build & run it as follows:
```
dune build @graphviz
```
## Limitations and Implementation
The library has been tested under Linux, MacOS, and Cygwin. There is experimental support for native Windows, but this is untested.
The implementation uses
* `xdg-open` on Linux
* `open` on MacOS
* `cygstart` on Cygiwn, and
* `cmd start` on Windows.
## Suggestion and Contributions
Suggestions and contributions are always welcome. Feel free to submit pull requests.