man-pages/man3/File::MimeInfo::Applications.3pm.html
2021-03-31 01:06:50 +01:00

201 lines
5.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of File::MimeInfo::Applications</TITLE>
</HEAD><BODY>
<H1>File::MimeInfo::Applications</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2018-08-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
File::MimeInfo::Applications - Find programs to open a file by mimetype
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use File::MimeInfo::Magic;
use File::MimeInfo::Applications;
my $file = '/foo/bar';
my $mimetype = mimetype($file)
|| die &quot;Could not find mimetype for $file\n&quot;;
my ($default, @other) = mime_applications($mimetype);
if (defined $default) {
$default-&gt;system($file)
}
else {
# prompt user with choice from @others
# ...
}
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
This module tries to find applications that can open files
with a certain mimetype. This is done in the way suggested by
the freedesktop Desktop Entry specification. This module is
intended to be compatible with file managers and other applications that
implement this specification.
<P>
This module depends on File::DesktopEntry being installed.
<P>
To use this module effectively you need to have the desktop-file-utils
package from freedesktop and run update-desktop-database after installing
new .desktop files.
See &lt;<A HREF="http://www.freedesktop.org/wiki/Software/desktop-file-utils">http://www.freedesktop.org/wiki/Software/desktop-file-utils</A>&gt;.
<P>
At the moment of writing this module is compatible with the way Nautilus (Gnome)
and with Thunar (<FONT SIZE="-1">XFCE</FONT>) handle applications for mimetypes. I understand <FONT SIZE="-1">KDE</FONT>
is still working on implementing the freedesktop mime specifications but will
follow. At the very least all perl applications using this module are using
the same defaults.
<A NAME="lbAE">&nbsp;</A>
<H2>EXPORT</H2>
All methods are exported by default.
<A NAME="lbAF">&nbsp;</A>
<H2>METHODS</H2>
<DL COMPACT>
<DT id="1">&quot;mime_applications(MIMETYPE)&quot;<DD>
Returns an array of File::DesktopEntry objects. The first
is the default application for this mimetype, the rest are
applications that say they can handle this mimetype.
<P>
If the first result is undefined there is no default application
and it is good practice to ask the user which application he wants
to use.
<DT id="2">&quot;mime_applications_all(MIMETYPE)&quot;<DD>
Like <TT>&quot;mime_applications()&quot;</TT> but also takes into account applications that
can open mimetypes from which <FONT SIZE="-1">MIMETYPE</FONT> inherits. Parent mimetypes tell
something about the data format, all code inherits from text/plain for example.
<DT id="3">&quot;mime_applications_set_default(MIMETYPE, APPLICATION)&quot;<DD>
Save a default application for this mimetype. This action will
affect other applications using the same mechanism to find a default
application.
<P>
<FONT SIZE="-1">APPLICATION</FONT> can either be a File::DesktopEntry object or
the basename of a .desktop file.
<DT id="4">&quot;mime_applications_set_custom(MIMETYPE, COMMAND)&quot;<DD>
Save a custom shell command as default application.
Generates a DesktopEntry file on the fly and calls
<TT>&quot;mime_applications_set_custom&quot;</TT>.
Returns the DesktopEntry object.
<P>
No checks are done at all on <FONT SIZE="-1">COMMAND.</FONT>
It should however contain at least one word.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>NOTES</H2>
This module looks for associations files in the order specified in version 1.0
of the <FONT SIZE="-1">MIME</FONT> applications specification. It will also attempt a last-resort
fallback to the legacy file
<I></I>$XDG_DATA_HOME<I>/applications/defaults.list</I>. In all cases, it will only write
to the recommended per-user defaults file located at
<I></I>$XDG_CONFIG_HOME<I>/mimeapps.list</I>.
<A NAME="lbAH">&nbsp;</A>
<H2>AUTHOR</H2>
Jaap Karssenberg &lt;<A HREF="mailto:pardus@cpan.org">pardus@cpan.org</A>&gt;
Maintained by Michiel Beijen &lt;<A HREF="mailto:michiel.beijen@gmail.com">michiel.beijen@gmail.com</A>&gt;
<A NAME="lbAI">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright (c) 2005, 2012 Jaap G Karssenberg. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
File::DesktopEntry,
File::MimeInfo,
File::MimeInfo::Magic,
File::BaseDir
<P>
&lt;<A HREF="http://freedesktop.org/wiki/Software/desktop-file-utils/">http://freedesktop.org/wiki/Software/desktop-file-utils/</A>&gt;
&lt;<A HREF="http://freedesktop.org/wiki/Specifications/mime-apps-spec/">http://freedesktop.org/wiki/Specifications/mime-apps-spec/</A>&gt;
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="5"><A HREF="#lbAB">NAME</A><DD>
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="8"><A HREF="#lbAE">EXPORT</A><DD>
<DT id="9"><A HREF="#lbAF">METHODS</A><DD>
<DT id="10"><A HREF="#lbAG">NOTES</A><DD>
<DT id="11"><A HREF="#lbAH">AUTHOR</A><DD>
<DT id="12"><A HREF="#lbAI">COPYRIGHT</A><DD>
<DT id="13"><A HREF="#lbAJ">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:43 GMT, March 31, 2021
</BODY>
</HTML>