### List MIME Associations Source: https://github.com/freeslave/mimeapps/blob/master/README.md Use this command to list the default and associated applications for specified MIME types or URI schemes. Ensure the 'mimeapps' example is compiled. ```bash dub examples/list.d text/plain image/png text/html ``` ```bash dub examples/list.d x-scheme-handler/http ``` -------------------------------- ### DesktopFileProvider - Retrieve Desktop Files by ID Source: https://context7.com/freeslave/mimeapps/llms.txt Explains how to use the DesktopFileProvider to retrieve and cache desktop files by their desktop ID, including examples of initializing the provider with system or custom paths and accessing file properties. ```APIDOC ### DesktopFileProvider - Retrieve Desktop Files by ID ### Description The `DesktopFileProvider` class implements the `IDesktopFileProvider` interface to retrieve and cache desktop files by their desktop ID. ### Method ```d import mimeapps; import desktopfile.paths; // Create provider with system application paths auto provider = new DesktopFileProvider(applicationsPaths()); // Get desktop file by ID auto geanyDesktop = provider.getByDesktopId("geany.desktop"); if (geanyDesktop !is null) { writeln("Name: ", geanyDesktop.displayName()); writeln("Exec: ", geanyDesktop.execValue()); writeln("Icon: ", geanyDesktop.iconName()); writeln("Comment: ", geanyDesktop.comment()); // Check if it's a valid application if (geanyDesktop.desktopEntry.escapedValue("Exec").length != 0) { writeln("Valid application with Exec command"); } } // Create provider with custom paths and read options import desktopfile.file : DesktopFile; auto customProvider = new DesktopFileProvider( ["/opt/apps", "/home/user/.local/share/applications"], ["/usr/bin", "/usr/local/bin"], // bin paths for TryExec checking DesktopFile.DesktopReadOptions.init ); auto customApp = customProvider.getByDesktopId("myapp.desktop"); ``` ``` -------------------------------- ### Find Default Application for MIME Type Source: https://context7.com/freeslave/mimeapps/llms.txt Use `findDefaultApplication` to get the primary application for a MIME type. It searches mimeapps.list and mimeinfo.cache files. The returned application object can be used to display its name, execution command, and to launch it with a file. ```d import mimeapps; import desktopfile.paths; // Set up desktop file provider and file sources auto provider = new DesktopFileProvider(applicationsPaths()); auto mimeAppsLists = mimeAppsListFiles(); auto mimeInfoCaches = mimeInfoCacheFiles(); // Find default application for text files auto defaultApp = findDefaultApplication("text/plain", mimeAppsLists, mimeInfoCaches, provider); if (defaultApp !is null) { writeln("Default app: ", defaultApp.displayName()); // Output: Default app: Geany writeln("Exec: ", defaultApp.execValue()); // Output: Exec: geany %F writeln("File: ", defaultApp.fileName); // Output: File: /usr/share/applications/geany.desktop // Start the application with a file defaultApp.startApplication("/path/to/file.txt"); } else { writeln("No default application found"); } // Find default application for URL scheme handler auto browserApp = findDefaultApplication("x-scheme-handler/http", mimeAppsLists, mimeInfoCaches, provider); if (browserApp !is null) { writeln("Default browser: ", browserApp.displayName()); // Output: Default browser: Firefox } // Find default application for PDF files auto pdfApp = findDefaultApplication("application/pdf", mimeAppsLists, mimeInfoCaches, provider); if (pdfApp !is null) { writeln("PDF viewer: ", pdfApp.displayName()); // Output: PDF viewer: Okular } ``` -------------------------------- ### Retrieve Desktop Files by ID with DesktopFileProvider Source: https://context7.com/freeslave/mimeapps/llms.txt The `DesktopFileProvider` retrieves and caches desktop files using their unique desktop IDs. It can be initialized with system application paths or custom directories. ```d import mimeapps; import desktopfile.paths; // Create provider with system application paths auto provider = new DesktopFileProvider(applicationsPaths()); // Get desktop file by ID auto geanyDesktop = provider.getByDesktopId("geany.desktop"); if (geanyDesktop !is null) { writeln("Name: ", geanyDesktop.displayName()); writeln("Exec: ", geanyDesktop.execValue()); writeln("Icon: ", geanyDesktop.iconName()); writeln("Comment: ", geanyDesktop.comment()); // Check if it's a valid application if (geanyDesktop.desktopEntry.escapedValue("Exec").length != 0) { writeln("Valid application with Exec command"); } } // Create provider with custom paths and read options import desktopfile.file : DesktopFile; auto customProvider = new DesktopFileProvider( ["/opt/apps", "/home/user/.local/share/applications"], ["/usr/bin", "/usr/local/bin"], // bin paths for TryExec checking DesktopFile.DesktopReadOptions.init ); auto customApp = customProvider.getByDesktopId("myapp.desktop"); ``` -------------------------------- ### Discover Freedesktop Path Functions Source: https://context7.com/freeslave/mimeapps/llms.txt These functions help locate standard mimeapps.list and mimeinfo.cache files on Freedesktop-compliant systems. They cover user, system, vendor, and distribution-specific paths. ```d import mimeapps; // Get all mimeapps.list file paths (user and system) auto allPaths = mimeAppsListPaths(); foreach(path; allPaths) { writeln("mimeapps.list: ", path); } // Get user-specific mimeapps.list paths auto userPaths = userMimeAppsListPaths(); foreach(path; userPaths) { writeln("User mimeapps.list: ", path); } // Get vendor/sysadmin override paths auto vendorPaths = vendorMimeAppsListPaths(); foreach(path; vendorPaths) { writeln("Vendor mimeapps.list: ", path); } // Get distribution default paths auto distPaths = distributionMimeAppsListPaths(); foreach(path; distPaths) { writeln("Distribution mimeapps.list: ", path); } // Get all mimeinfo.cache paths auto cachePaths = mimeInfoCachePaths(); foreach(path; cachePaths) { writeln("mimeinfo.cache: ", path); } // Get desktop environment prefixes (from XDG_CURRENT_DESKTOP) auto prefixes = getDesktopPrefixes(); foreach(prefix; prefixes) { writeln("Desktop prefix: ", prefix); } ``` -------------------------------- ### Open File with Default Application Source: https://github.com/freeslave/mimeapps/blob/master/README.md Detects the MIME type of a given file and opens it with the default associated application. Use the --ask flag to see all associated applications before opening. ```bash dub examples/open.d LICENSE_1_0.txt ``` ```bash dub examples/open.d --ask LICENSE_1_0.txt ``` ```bash dub examples/open.d --ask https://github.com/FreeSlave/mimeapps ``` -------------------------------- ### Handle empty input for joinApps Source: https://context7.com/freeslave/mimeapps/llms.txt When `joinApps` receives a null or empty array, it returns an empty string. ```d // Empty input handling assert(MimeAppsGroup.joinApps(cast(string[])null) == string.init); ``` -------------------------------- ### Split semicolon-separated app list Source: https://context7.com/freeslave/mimeapps/llms.txt Use `splitApps` to parse a semicolon-separated string of desktop IDs into an array. Asserts that the resulting array matches the expected list. ```d import mimeapps; // Split a semicolon-separated list of apps auto apps = MimeAppsGroup.splitApps("kde4-kate.desktop;kde4-kwrite.desktop;geany.desktop;"); assert(apps.equal(["kde4-kate.desktop", "kde4-kwrite.desktop", "geany.desktop"])); ``` -------------------------------- ### AssociationUpdateQuery - Build and Apply Association Updates Source: https://context7.com/freeslave/mimeapps/llms.txt Demonstrates how to use the AssociationUpdateQuery struct to build and apply updates to mimeapps.list files. This includes adding, removing, and setting default applications, as well as applying the query to a file or directly to a file path. ```APIDOC ## AssociationUpdateQuery - Build and Apply Association Updates ### Description The `AssociationUpdateQuery` struct allows building reusable queries for updating file associations that can be applied to multiple mimeapps.list files. ### Method ```d import mimeapps; // Build an update query AssociationUpdateQuery query; query.addAssociation("text/plain", "geany.desktop"); query.removeAssociation("text/plain", "kde4-okular.desktop"); query.setDefaultApplication("text/plain", "kde4-kate.desktop"); query.setAddedAssocations("image/png", ["kde4-gwenview.desktop", "gthumb.desktop"]); // Apply query to a new file auto file = new MimeAppsListFile(); query.apply(file); // Verify the changes assert(file.defaultApplications().appsForMimeType("text/plain").equal(["kde4-kate.desktop"])); assert(file.addedAssociations().appsForMimeType("text/plain").equal(["kde4-kate.desktop", "geany.desktop"])); assert(file.removedAssociations().appsForMimeType("text/plain").equal(["kde4-okular.desktop"])); assert(file.addedAssociations().appsForMimeType("image/png").equal(["kde4-gwenview.desktop", "gthumb.desktop"])); // Save to file file.saveToFile("/tmp/mimeapps.list"); // Or use updateAssociations to apply directly to a file path updateAssociations("/home/user/.config/mimeapps.list", query); ``` ``` -------------------------------- ### Path Discovery Functions (Freedesktop Only) Source: https://context7.com/freeslave/mimeapps/llms.txt Provides functions to discover standard file locations for mimeapps.list and mimeinfo.cache on Freedesktop-compliant systems, including user, system, vendor, and distribution paths. ```APIDOC ### Path Discovery Functions (Freedesktop Only) ### Description These functions discover the standard locations for mimeapps.list and mimeinfo.cache files on Freedesktop-compliant systems. ### Method ```d import mimeapps; // Get all mimeapps.list file paths (user and system) auto allPaths = mimeAppsListPaths(); foreach(path; allPaths) { writeln("mimeapps.list: ", path); } // Get user-specific mimeapps.list paths auto userPaths = userMimeAppsListPaths(); foreach(path; userPaths) { writeln("User mimeapps.list: ", path); } // Get vendor/sysadmin override paths auto vendorPaths = vendorMimeAppsListPaths(); foreach(path; vendorPaths) { writeln("Vendor mimeapps.list: ", path); } // Get distribution default paths auto distPaths = distributionMimeAppsListPaths(); foreach(path; distPaths) { writeln("Distribution mimeapps.list: ", path); } // Get all mimeinfo.cache paths auto cachePaths = mimeInfoCachePaths(); foreach(path; cachePaths) { writeln("mimeinfo.cache: ", path); } // Get desktop environment prefixes (from XDG_CURRENT_DESKTOP) auto prefixes = getDesktopPrefixes(); foreach(prefix; prefixes) { writeln("Desktop prefix: ", prefix); } ``` ``` -------------------------------- ### Parse and Manipulate mimeapps.list Files with MimeAppsListFile Source: https://context7.com/freeslave/mimeapps/llms.txt Use MimeAppsListFile to read, access, create, and save mimeapps.list files. It supports accessing default, added, and removed application associations for MIME types. ```d import mimeapps; // Read an existing mimeapps.list file auto mimeAppsList = new MimeAppsListFile("/home/user/.config/mimeapps.list"); // Access default applications group auto defaultApps = mimeAppsList.defaultApplications(); if (defaultApps !is null) { // Get default app for text/plain auto apps = defaultApps.appsForMimeType("text/plain"); foreach(desktopId; apps) { writeln("Default: ", desktopId); // Output: Default: geany.desktop } } // Access added associations group auto addedApps = mimeAppsList.addedAssociations(); if (addedApps !is null) { auto apps = addedApps.appsForMimeType("text/plain"); foreach(desktopId; apps) { writeln("Added: ", desktopId); // Output: Added: geany.desktop, Added: kate.desktop } } // Create a new mimeapps.list file from scratch auto newFile = new MimeAppsListFile(); newFile.setDefaultApplication("text/plain", "geany.desktop"); newFile.addAssociation("text/plain", "kate.desktop"); newFile.removeAssociation("text/plain", "libreoffice.desktop"); newFile.saveToFile("/tmp/mimeapps.list"); // Parse from string content string content = `[Default Applications] text/plain=kde4-kate.desktop [Added Associations] text/plain=kde4-kate.desktop;emacs.desktop;`; auto parsedFile = new MimeAppsListFile(iniLikeStringReader(content)); assert(parsedFile.defaultApplications().appsForMimeType("text/plain").equal(["kde4-kate.desktop"])); ``` -------------------------------- ### Find All Known Applications Including Removed Source: https://context7.com/freeslave/mimeapps/llms.txt The `findKnownAssociatedApplications` function lists all applications known to handle a MIME type, including those that have been explicitly removed by the user from associations. This is useful for understanding the full scope of potential handlers. ```d import mimeapps; import desktopfile.paths; auto provider = new DesktopFileProvider(applicationsPaths()); auto mimeAppsLists = mimeAppsListFiles(); auto mimeInfoCaches = mimeInfoCacheFiles(); // Get all known applications (including those user has removed from associations) auto knownApps = findKnownAssociatedApplications("text/plain", mimeAppsLists, mimeInfoCaches, provider); writeln("All known applications for text/plain (including removed):"); foreach(desktopFile; knownApps) { writefln(" - %s", desktopFile.displayName()); } // Output includes apps that user removed from "Added Associations": // - Geany // - Kate // - Emacs // - Okular (was in Removed Associations) ``` -------------------------------- ### Find All Associated Applications for MIME Type Source: https://context7.com/freeslave/mimeapps/llms.txt Use `findAssociatedApplications` to retrieve a list of all applications that can open a specific MIME type, respecting explicitly removed associations. This function returns `DesktopFile` objects for each associated application. ```d import mimeapps; import desktopfile.paths; auto provider = new DesktopFileProvider(applicationsPaths()); auto mimeAppsLists = mimeAppsListFiles(); auto mimeInfoCaches = mimeInfoCacheFiles(); // Find all applications associated with text/plain auto associatedApps = findAssociatedApplications("text/plain", mimeAppsLists, mimeInfoCaches, provider); writeln("Applications for text/plain:"); foreach(desktopFile; associatedApps) { writefln(" - %s (%s)", desktopFile.displayName(), desktopFile.fileName); } // Output: // - Geany (/usr/share/applications/geany.desktop) // - Kate (/usr/share/applications/kate.desktop) // - Emacs (/usr/share/applications/emacs.desktop) // Find applications for image files auto imageApps = findAssociatedApplications("image/png", mimeAppsLists, mimeInfoCaches, provider); foreach(app; imageApps) { writefln("Image viewer: %s", app.displayName()); } // Use listAssociatedApplications to get just desktop IDs (without loading .desktop files) string[] desktopIds = listAssociatedApplications("text/plain", mimeAppsLists, mimeInfoCaches); foreach(id; desktopIds) { writeln("Desktop ID: ", id); // Output: Desktop ID: geany.desktop } ``` -------------------------------- ### Build and Apply Association Updates with AssociationUpdateQuery Source: https://context7.com/freeslave/mimeapps/llms.txt Use `AssociationUpdateQuery` to define reusable updates for file associations. Apply these queries to new or existing `MimeAppsListFile` objects, or directly to a file path using `updateAssociations`. ```d import mimeapps; // Build an update query AssociationUpdateQuery query; query.addAssociation("text/plain", "geany.desktop"); query.removeAssociation("text/plain", "kde4-okular.desktop"); query.setDefaultApplication("text/plain", "kde4-kate.desktop"); query.setAddedAssocations("image/png", ["kde4-gwenview.desktop", "gthumb.desktop"]); // Apply query to a new file auto file = new MimeAppsListFile(); query.apply(file); // Verify the changes assert(file.defaultApplications().appsForMimeType("text/plain").equal(["kde4-kate.desktop"])); assert(file.addedAssociations().appsForMimeType("text/plain").equal(["kde4-kate.desktop", "geany.desktop"])); assert(file.removedAssociations().appsForMimeType("text/plain").equal(["kde4-okular.desktop"])); assert(file.addedAssociations().appsForMimeType("image/png").equal(["kde4-gwenview.desktop", "gthumb.desktop"])); // Save to file file.saveToFile("/tmp/mimeapps.list"); // Or use updateAssociations to apply directly to a file path updateAssociations("/home/user/.config/mimeapps.list", query); ``` -------------------------------- ### Join app list into semicolon-separated string Source: https://context7.com/freeslave/mimeapps/llms.txt Use `joinApps` to convert an array of desktop IDs into a semicolon-separated string. By default, it includes a trailing semicolon. ```d // Join list of apps into semicolon-separated string auto joined = MimeAppsGroup.joinApps(["kate.desktop", "kwrite.desktop", "geany.desktop"]); assert(joined == "kate.desktop;kwrite.desktop;geany.desktop;"); ``` -------------------------------- ### List Associated Applications (Desktop IDs Only) Source: https://context7.com/freeslave/mimeapps/llms.txt Retrieves a list of desktop IDs for applications associated with a MIME type, without loading the full DesktopFile objects. ```APIDOC ## listAssociatedApplications ### Description Returns a list of desktop IDs for applications associated with a given MIME type. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```d import mimeapps; import desktopfile.paths; auto mimeAppsLists = mimeAppsListFiles(); auto mimeInfoCaches = mimeInfoCacheFiles(); string[] desktopIds = listAssociatedApplications("text/plain", mimeAppsLists, mimeInfoCaches); foreach(id; desktopIds) { writeln("Desktop ID: ", id); } ``` ### Response #### Success Response (200) - **desktopIds** (Array) - An array of strings, where each string is a desktop ID. #### Response Example ```json [ "geany.desktop", "kate.desktop" ] ``` ``` -------------------------------- ### Update Mimeapps.list File Source: https://github.com/freeslave/mimeapps/blob/master/README.md This command updates a mimeapps.list file. Use the --force flag to apply changes directly to your system's configuration, but it is recommended to back up the file first. You can add, remove, or set default applications. ```bash cp $HOME/.config/mimeapps.list /tmp/mimeapps.list dub examples/update.d --file=/tmp/mimeapps.list --remove=text/plain:kde4-kwrite.desktop --add=image/jpeg:gthumb.desktop --default=application/pdf:kde4-okular.desktop ``` -------------------------------- ### MimeAppsListFile - Parse and Manipulate mimeapps.list Files Source: https://context7.com/freeslave/mimeapps/llms.txt The MimeAppsListFile class represents a single mimeapps.list file. It allows reading, accessing, and modifying default applications, added associations, and removed associations. New files can be created and saved, and files can also be parsed from string content. ```APIDOC ## MimeAppsListFile - Parse and Manipulate mimeapps.list Files ### Description The `MimeAppsListFile` class represents a single mimeapps.list file containing information about MIME type associations and default applications. It provides access to default applications, added associations, and removed associations groups. ### Method - `new MimeAppsListFile(string filePath)`: Reads an existing mimeapps.list file from the specified path. - `new MimeAppsListFile()`: Creates a new, empty MimeAppsListFile. - `new MimeAppsListFile(InputRange)`: Parses mimeapps.list content from an InputRange. ### Parameters #### Path Parameters - `filePath` (string) - Required - The path to the mimeapps.list file. #### Request Body (Not applicable for file parsing/creation) ### Request Example ```d import mimeapps; // Read an existing mimeapps.list file auto mimeAppsList = new MimeAppsListFile("/home/user/.config/mimeapps.list"); // Access default applications group auto defaultApps = mimeAppsList.defaultApplications(); if (defaultApps !is null) { // Get default app for text/plain auto apps = defaultApps.appsForMimeType("text/plain"); foreach(desktopId; apps) { writeln("Default: ", desktopId); // Output: Default: geany.desktop } } // Access added associations group auto addedApps = mimeAppsList.addedAssociations(); if (addedApps !is null) { auto apps = addedApps.appsForMimeType("text/plain"); foreach(desktopId; apps) { writeln("Added: ", desktopId); // Output: Added: geany.desktop, Added: kate.desktop } } // Create a new mimeapps.list file from scratch auto newFile = new MimeAppsListFile(); newFile.setDefaultApplication("text/plain", "geany.desktop"); newFile.addAssociation("text/plain", "kate.desktop"); newFile.removeAssociation("text/plain", "libreoffice.desktop"); newFile.saveToFile("/tmp/mimeapps.list"); // Parse from string content string content = `[Default Applications] text/plain=kde4-kate.desktop [Added Associations] text/plain=kde4-kate.desktop;emacs.desktop;`; auto parsedFile = new MimeAppsListFile(iniLikeStringReader(content)); assert(parsedFile.defaultApplications().appsForMimeType("text/plain").equal(["kde4-kate.desktop"])); ``` ### Response #### Success Response (200) - `MimeAppsListFile` object representing the parsed or created file. #### Response Example (See Request Example for code demonstrating access to parsed data) ``` -------------------------------- ### Read mimeinfo.cache Files with MimeInfoCacheFile Source: https://context7.com/freeslave/mimeapps/llms.txt Use MimeInfoCacheFile to read mimeinfo.cache files, which contain cached application associations for MIME types. These files are typically generated by update-desktop-database. ```d import mimeapps; // Read mimeinfo.cache file auto mimeInfoCache = new MimeInfoCacheFile("/usr/share/applications/mimeinfo.cache"); // Access MIME Cache group auto mimeCache = mimeInfoCache.mimeCache(); // Get all applications for a MIME type auto apps = mimeCache.appsForMimeType("text/plain"); foreach(desktopId; apps) { writeln("Cached app: ", desktopId); // Output: Cached app: geany.desktop // Output: Cached app: kate.desktop // Output: Cached app: emacs.desktop } // Parse from string content string content = `[MIME Cache] text/plain=geany.desktop;kde4-kwrite.desktop; image/png=kde4-gwenview.desktop;gthumb.desktop;`; auto cache = new MimeInfoCacheFile(iniLikeStringReader(content)); assert(cache.appsForMimeType("text/plain").equal(["geany.desktop", "kde4-kwrite.desktop"])); assert(cache.appsForMimeType("image/png").equal(["kde4-gwenview.desktop", "gthumb.desktop"])); ``` -------------------------------- ### Find All Known Applications Including Removed Source: https://context7.com/freeslave/mimeapps/llms.txt Returns all known applications capable of opening a given MIME type, including those explicitly removed by the user. ```APIDOC ## findKnownAssociatedApplications ### Description Returns all known applications for a MIME type, including those that the user has explicitly removed from associations. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```d import mimeapps; import desktopfile.paths; auto provider = new DesktopFileProvider(applicationsPaths()); auto mimeAppsLists = mimeAppsListFiles(); auto mimeInfoCaches = mimeInfoCacheFiles(); auto knownApps = findKnownAssociatedApplications("text/plain", mimeAppsLists, mimeInfoCaches, provider); foreach(desktopFile; knownApps) { writefln(" - %s", desktopFile.displayName()); } ``` ### Response #### Success Response (200) - **knownApps** (Array) - An array of DesktopFile objects representing all known applications for the MIME type, including removed ones. #### Response Example ```json [ { "displayName": "Geany" }, { "displayName": "Kate" }, { "displayName": "Okular" } ] ``` ``` -------------------------------- ### Find All Associated Applications Source: https://context7.com/freeslave/mimeapps/llms.txt Returns all applications capable of opening a given MIME type, respecting explicitly removed associations. ```APIDOC ## findAssociatedApplications ### Description Returns all applications associated with a given MIME type, excluding those explicitly removed by the user. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```d import mimeapps; import desktopfile.paths; auto provider = new DesktopFileProvider(applicationsPaths()); auto mimeAppsLists = mimeAppsListFiles(); auto mimeInfoCaches = mimeInfoCacheFiles(); auto associatedApps = findAssociatedApplications("text/plain", mimeAppsLists, mimeInfoCaches, provider); foreach(desktopFile; associatedApps) { writefln(" - %s (%s)", desktopFile.displayName(), desktopFile.fileName); } ``` ### Response #### Success Response (200) - **associatedApps** (Array) - An array of DesktopFile objects representing applications associated with the MIME type. #### Response Example ```json [ { "displayName": "Geany", "fileName": "/usr/share/applications/geany.desktop" }, { "displayName": "Kate", "fileName": "/usr/share/applications/kate.desktop" } ] ``` ``` -------------------------------- ### Test MIMEapps Parsing Source: https://github.com/freeslave/mimeapps/blob/master/README.md This command parses all mimeapps.list and mimeinfo.cache files found on the system and reports any parsing errors to stderr. It's useful for verifying the library's ability to handle system configuration files. ```bash dub examples/test.d ``` -------------------------------- ### Find Default Application for MIME Type Source: https://context7.com/freeslave/mimeapps/llms.txt Retrieves the default application for a given MIME type by searching through mimeapps.list and mimeinfo.cache files. ```APIDOC ## findDefaultApplication ### Description Finds the default application for a given MIME type. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```d import mimeapps; import desktopfile.paths; auto provider = new DesktopFileProvider(applicationsPaths()); auto mimeAppsLists = mimeAppsListFiles(); auto mimeInfoCaches = mimeInfoCacheFiles(); auto defaultApp = findDefaultApplication("text/plain", mimeAppsLists, mimeInfoCaches, provider); if (defaultApp !is null) { writeln("Default app: ", defaultApp.displayName()); writeln("Exec: ", defaultApp.execValue()); writeln("File: ", defaultApp.fileName); defaultApp.startApplication("/path/to/file.txt"); } else { writeln("No default application found"); } ``` ### Response #### Success Response (200) - **defaultApp** (DesktopFile) - The default application object if found, otherwise null. #### Response Example ```json { "displayName": "Geany", "execValue": "geany %F", "fileName": "/usr/share/applications/geany.desktop" } ``` ``` -------------------------------- ### Join app list without trailing semicolon Source: https://context7.com/freeslave/mimeapps/llms.txt Call `joinApps` with `false` as the second argument to omit the trailing semicolon from the resulting string. ```d // Join without trailing semicolon auto joinedNoTrail = MimeAppsGroup.joinApps(["geany.desktop"], false); assert(joinedNoTrail == "geany.desktop"); ``` -------------------------------- ### MimeInfoCacheFile - Read mimeinfo.cache Files Source: https://context7.com/freeslave/mimeapps/llms.txt The MimeInfoCacheFile class represents a mimeinfo.cache file, which stores cached information about applications that can handle specific MIME types. These files are typically generated by the update-desktop-database utility. ```APIDOC ## MimeInfoCacheFile - Read mimeinfo.cache Files ### Description The `MimeInfoCacheFile` class represents a mimeinfo.cache file that contains cached information about which applications can handle which MIME types. These files are generated by `update-desktop-database` utility. ### Method - `new MimeInfoCacheFile(string filePath)`: Reads a mimeinfo.cache file from the specified path. - `new MimeInfoCacheFile(InputRange)`: Parses mimeinfo.cache content from an InputRange. ### Parameters #### Path Parameters - `filePath` (string) - Required - The path to the mimeinfo.cache file. #### Request Body (Not applicable for file parsing) ### Request Example ```d import mimeapps; // Read mimeinfo.cache file auto mimeInfoCache = new MimeInfoCacheFile("/usr/share/applications/mimeinfo.cache"); // Access MIME Cache group auto mimeCache = mimeInfoCache.mimeCache(); // Get all applications for a MIME type auto apps = mimeCache.appsForMimeType("text/plain"); foreach(desktopId; apps) { writeln("Cached app: ", desktopId); // Output: Cached app: geany.desktop // Output: Cached app: kate.desktop // Output: Cached app: emacs.desktop } // Parse from string content string content = `[MIME Cache] text/plain=geany.desktop;kde4-kwrite.desktop; image/png=kde4-gwenview.desktop;gthumb.desktop;`; auto cache = new MimeInfoCacheFile(iniLikeStringReader(content)); assert(cache.appsForMimeType("text/plain").equal(["geany.desktop", "kde4-kwrite.desktop"])); assert(cache.appsForMimeType("image/png").equal(["kde4-gwenview.desktop", "gthumb.desktop"])); ``` ### Response #### Success Response (200) - `MimeInfoCacheFile` object representing the parsed cache. #### Response Example (See Request Example for code demonstrating access to parsed data) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.