How to Use the Command 'handlr' (with Examples)
- Linux
- December 17, 2024
Handlr is a versatile command-line tool designed to manage default applications on your system. It allows you to set and modify which applications handle specific file types or protocols, ensuring that your files open in the desired program every time. With Handlr, users can customize their workflows for efficiency and convenience by tailoring file associations according to personal preferences. Below, we explore various use cases of this command, showing how to open URLs and files, set and retrieve default applications for specific file types, and more.
Use case 1: Open a URL in the Default Application
Code:
handlr open https://example.com
Motivation:
Opening URLs directly from the command line can save time, especially when working in environments where graphical user interfaces are minimized or when operating remotely via SSH. This approach streamlines the process of quickly accessing web resources without the need to manually enter URLs into a browser.
Explanation:
handlr
: The primary command to manage default applications.open
: This argument instructs Handlr to open the subsequent URL in the system’s default web browser.https://example.com
: The URL to be opened. Handlr resolves this by launching the browser associated with opening HTTP links.
Example Output:
Upon execution, a web browser opens and navigates to the specified URL, https://example.com
, without displaying any output in the terminal.
Use case 2: Open a PDF in the Default PDF Viewer
Code:
handlr open path/to/file.pdf
Motivation:
Quickly accessing documents via command-line can enhance productivity, especially for users who frequently navigate directories and files in terminal sessions. By using Handlr, you can seamlessly open PDFs in your preferred viewer without additional steps.
Explanation:
handlr
: Invokes the tool designed to handle default applications.open
: Signals to Handlr to launch an application to open the following file.path/to/file.pdf
: Specifies the path to the PDF file you want to open. Handlr uses the system’s default PDF viewer to do so.
Example Output:
Executing this command opens the specified PDF in the default viewer, such as Adobe Reader or a built-in PDF application, directly presenting the document to the user.
Use case 3: Set imv
as the Default Application for PNG Files
Code:
handlr set .png imv.desktop
Motivation:
Customizing the default application for specific file types allows users to better integrate software tools that enhance their workflow. If imv
is a preferred image viewer, setting it as the default for PNG files ensures all PNGs are automatically opened by it, saving time and enhancing user experience.
Explanation:
handlr
: The command tool used for associating file types with applications.set
: Indicates an operation to assign a new default application..png
: The file extension for which the default application is being set.imv.desktop
: The desktop entry id for the applicationimv
, indicating it should be the default handler for.png
files.
Example Output:
The command confirms that the default application for PNG files has been set to imv
, updating any system configurations necessary for the association.
Use case 4: Set MPV as the Default Application for All Audio Files
Code:
handlr set 'audio/*' mpv.desktop
Motivation:
By setting a reliable media player like MPV as the default for audio files, users gain consistency in playback quality and support across various formats automatically. This adjustment ensures every audio file is directed to a preferred, capable application.
Explanation:
handlr
: The tool for configuring default file handlers.set
: Begins the process of defining default application settings.'audio/*'
: A wildcard pattern representing any audio file type, making this setting comprehensive across the system.mpv.desktop
: Refers to the application identifier for MPV, setting it as the default player for audio files.
Example Output:
The system confirms new associations have been made, and MPV will now handle all audio files by default.
Use case 5: List All Default Apps
Code:
handlr list
Motivation:
Listing all current default applications allows users to review or audit how their system is configured. This overview helps ensure that all file types are managed by suitable applications and can lead to system optimizations or corrections.
Explanation:
handlr
: Commands the utility to execute functions related to application management.list
: Requests a comprehensive display of all file type to application mappings on the system.
Example Output:
The terminal lists each file type extension or MIME type paired with its respective default application, such as PDF files with a particular viewer or image files with a designated editor.
Use case 6: Print the Default Application for PNG Files
Code:
handlr get .png
Motivation:
Knowing the current default application for a specific file type is crucial for debugging or confirming configuration settings. This function is helpful during system setups or when transitioning to new software solutions, providing clarity on file associations.
Explanation:
handlr
: The app handling command-line file associations.get
: Specifies a request for information regarding default application settings..png
: The file extension for which the current default application is being queried.
Example Output:
The terminal outputs the current default application for handling PNG files, showing something like imv.desktop
if it was previously set.
Conclusion:
Handlr provides a robust set of functionalities tailored for users who want finer control over how their systems manage default applications for various file types and protocols. From setting preferences to auditing current settings, Handlr simplifies the management of file associations, ensuring productivity is enhanced and user configurations are respected across different tasks and environments.