Desktop::Open - Open a file or URL in the user's preferred application
This document describes version 0.004 of Desktop::Open (from Perl distribution Desktop-Open), released on 2023-10-21.
use Desktop::Open qw(open_desktop); my $ok = open_desktop($path_or_url); # !defined($ok); no recognized command found # $ok == 0; command found and executed # $ok != 0; command found, error while executing
This module tries to open specified file or URL in the user's preferred application. Here's how it does it.
1. If on Windows, use "start". If on other OS, use "xdg-open" if available.
2. If #1 fails, resort to using Browser::Open's open_browser. Return its return value. An exception is if #1 fails with "file/URL does not exist" error, in which case we give up immediately.
open_browser
TODO: On OSX, use "openit". Any taker?
String. Override which program to use for opening the progrm instead of xdg-open. Note that the program is not checked for existence, nor the result is checked for success. No other program will be tried.
Integer. If set to 1, then will just use Browser::Open directly instead of xdg-open program.
Please visit the project's homepage at https://metacpan.org/release/Desktop-Open.
Source repository is at https://github.com/perlancar/perl-Desktop-Open.
Browser::Open, on which our module is modelled upon.
Open::This also tries to do "The Right Thing" when opening files, but it's heavily towards text editor and git/GitHub.
App::Open and its CLI openit also attempt to open file using appropriate file. It requires setting up a configuration file to run.
perlancar <perlancar@cpan.org>
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
This software is copyright (c) 2023, 2021 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Desktop-Open
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
To install Desktop::Open, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Desktop::Open
CPAN shell
perl -MCPAN -e shell install Desktop::Open
For more information on module installation, please visit the detailed CPAN module installation guide.