Customizing Default Applications on macOS using duti (with examples)

Customizing Default Applications on macOS using duti (with examples)

  • Osx
  • November 5, 2023

Introduction

When working on macOS, it can be frustrating to have to manually select the default application for every file type or URL scheme. However, with the duti command, you can easily set default applications for document types and URL schemes on macOS. In this article, we will explore different use cases of the duti command and provide code examples to illustrate each one.

1: Set Safari as the default handler for HTML documents

The following command sets Safari as the default handler for HTML documents:

duti -s com.apple.Safari public.html all

Motivation: By setting Safari as the default handler for HTML documents, you ensure that whenever you open an HTML file or click on an HTML link, it will automatically open in Safari.

Explanation:

  • -s: Specifies that we want to set the default application.
  • com.apple.Safari: Represents the bundle identifier of Safari.
  • public.html: Represents the UTI (Uniform Type Identifier) for HTML documents.
  • all: Applies the change to all users.

Example Output:

No output is displayed if the command is successful.

2: Set VLC as the default viewer for files with .m4v extensions

The following command sets VLC as the default viewer for files with .m4v extensions:

duti -s org.videolan.vlc m4v viewer

Motivation: If you frequently work with video files in the .m4v format, setting VLC as the default viewer ensures that you can easily and quickly open these files without having to manually select VLC every time.

Explanation:

  • -s: Specifies that we want to set the default application.
  • org.videolan.vlc: Represents the bundle identifier of VLC.
  • m4v: Represents the file extension for .m4v files.
  • viewer: Specifies that we want to set VLC as the default viewer for this file type.

Example Output:

No output is displayed if the command is successful.

3: Set Finder as the default handler for the ftp:// URL scheme

The following command sets Finder as the default handler for the ftp:// URL scheme:

duti -s com.apple.Finder "ftp"

Motivation: By setting Finder as the default handler for ftp:// URLs, you can easily open FTP links without having to manually copy and paste them into a specific FTP client application.

Explanation:

  • -s: Specifies that we want to set the default application.
  • com.apple.Finder: Represents the bundle identifier of Finder.
  • "ftp": Represents the URL scheme we want to set the default handler for. Note the quotes around "ftp" to prevent any shell parsing issues.

Example Output:

No output is displayed if the command is successful.

4: Display information about the default application for a given extension

The following command displays information about the default application for a given extension:

duti -x ext

Motivation: If you are curious about the default application associated with a particular file extension, you can use this command to retrieve the information.

Explanation:

  • -x: Specifies that we want to display the default application for a given extension.
  • ext: Represents the file extension for which we want to retrieve the default application information.

Example Output:

The command will output the bundle identifier and the application name associated with the given extension, for example:

com.apple.Safari: Safari

5: Display the default handler for a given UTI

The following command displays the default handler for a given Uniform Type Identifier (UTI):

duti -d uti

Motivation: If you want to know which application is set as the default handler for a specific UTI, this command will provide the information you need.

Explanation:

  • -d: Specifies that we want to display the default handler for a given UTI.
  • uti: Represents the Uniform Type Identifier for which we want to retrieve the default handler information.

Example Output:

The command will output the bundle identifier and the application name associated with the given UTI, for example:

com.apple.Safari: Safari

6: Display all handlers of a given UTI

The following command displays all handlers of a given Uniform Type Identifier (UTI):

duti -l uti

Motivation: If you want to see all the applications that can handle a particular UTI, this command will provide a list of all the handlers.

Explanation:

  • -l: Specifies that we want to display all handlers of a given UTI.
  • uti: Represents the Uniform Type Identifier for which we want to retrieve the handlers list.

Example Output:

The command will output a list of bundle identifiers and application names that can handle the given UTI, for example:

com.apple.Safari: Safari
com.google.Chrome: Google Chrome

Conclusion

By leveraging the duti command, you can easily customize default applications for document types and URL schemes on macOS. Whether you want to set a default handler for a specific document type or view all the available handlers for a given UTI, duti provides the necessary functionality. Using the code examples provided in this article, you can easily set up and manage default applications according to your preferences.

Remember, with duti, you have the power to personalize your macOS experience by choosing the default applications that suit your needs.

Tags :

Related Posts

Managing Packages in Termux (with examples)

Managing Packages in Termux (with examples)

Termux is a powerful terminal emulator and Linux environment for Android, which allows users to run a wide range of Linux packages and utilities on their mobile devices.

Read More
How to use the command 'ddev' (with examples)

How to use the command 'ddev' (with examples)

The ‘ddev’ command is a container-based local development tool specifically designed for PHP environments.

Read More
Using the `picom` Command (with examples)

Using the `picom` Command (with examples)

Enable picom during a session picom & Motivation: Enabling picom during a session allows you to have transparency and window fading effects in your Xorg desktop environment.

Read More