
desktop.pl -- Interact with the desktop environment
This library provides access to the desktop environment of the user. Currently it only provides desktop_open/1,2, which hands a document over to the application the desktop associates with it.
desktop_open(+Document) is det
desktop_open(+Document, +Options) is det- Open Document using the application the desktop associates with
it, e.g., a PDF viewer for a `.pdf` file or a file browser if
Document is a directory. Document is one of
- A URL, i.e., text for which uri_is_global/1 is true, such as
https://www.swi-prolog.orgormailto:bugs@example.com. The URL is passed to the opener unmodified. - A file or directory. This is either a plain file name, a term
Dir/File or a file alias such as library(lists). If a plain
file name does not exist as given it is expanded using
expand_file_name/2, i.e.,
~,$varand wildcards are expanded and all matching files are opened.
Options processed:
- opener(+Command)
- Use Command instead of the platform default. Command is a
specification for process_which/2, a term
Command-Argsto pass the arguments Args before Document orwin_shellto use the Windows ShellExecute() API. - wait(+Boolean)
- If
true, wait for the opener to complete and raise an exception if it fails. This does not wait for the application: openers such asxdg-openmerely hand the document to the desktop and complete immediately, normally with success regardless of what the desktop does with it. Default isfalse, which starts the opener using thedetached(true)option of process_create/3. The option is ignored ifwin_shellis used, which never waits.
The command to use is taken from the first of these that yields an available command:
- The option
opener(Command) - The Prolog flag
desktop_openerif it is notdefault. It uses the same syntax as theopener(Command)option. - The Windows ShellExecute() API (see win_shell/2)
openon MacOScygstart(Cygwin),termux-open(Android/Termux) orwslview(WSL without a Linux desktop)xdg-open(freedesktop.org), followed by the desktop specificgio,gnome-open,kde-open,kde-open5andexo-openwslview,handlr,mimeopenorrun-mailcapopen, unless we are on Linux, whereopenis an alias foropenvt(1)rather than a document opener.
- A URL, i.e., text for which uri_is_global/1 is true, such as