How to Use the Command 'duti' on macOS (with Examples)
- Osx
- December 17, 2024
The duti
command is a powerful utility for macOS users who want to customize their experience by setting default applications for various document types and URL schemes. This is particularly useful for those who regularly work with multiple applications and need to streamline their workflow by specifying which applications should handle particular files or protocols.
Use Case 1: Set Safari as the Default Handler for HTML Documents
Code:
duti -s com.apple.Safari public.html all
Motivation:
Many macOS users prefer Safari for its integration with the Apple ecosystem, speed, and resource efficiency. By setting Safari as the default handler for HTML documents, users can ensure consistency in their browsing experience, especially when dealing with HTML files saved locally or received via email.
Explanation:
-s
: This flag signifies setting a new default application.com.apple.Safari
: This is the unique identifier (Bundle ID) for the Safari application.public.html
: This is the Uniform Type Identifier (UTI) which represents HTML document types.all
: This parameter indicates that Safari should handle all actions (e.g., opening, viewing) associated with HTML documents.
Example Output:
On successful execution, there is no output. However, if you open an HTML document by double-clicking, Safari will now launch to display the content.
Use Case 2: Set VLC as the Default Viewer for Files with .m4v
Extensions
Code:
duti -s org.videolan.vlc m4v viewer
Motivation:
VLC media player is renowned for its ability to play almost any media file format. Users who frequently handle .m4v
files, which are commonly used for video content, might prefer VLC due to its extensive feature set and support for various codecs and subtitles.
Explanation:
-s
: The setting flag to establish a new default.org.videolan.vlc
: The Bundle ID for VLC media player.m4v
: The file extension for video files that VLC will handle.viewer
: This action specifies that VLC should be used to view these files.
Example Output:
Success is indicated by the absence of errors. Post-configuration, .m4v
files will open with VLC when double-clicked.
Use Case 3: Set Finder as the Default Handler for the ftp:// URL Scheme
Code:
duti -s com.apple.Finder "ftp"
Motivation:
Some users prefer using Finder, macOS’s default file manager, to manage FTP connections due to its intuitive drag-and-drop interface and straightforward file navigation capabilities. This setup is particularly appealing for those who need to access FTP servers quickly without additional software.
Explanation:
-s
: Initiates the command for setting a default.com.apple.Finder
: The Bundle ID for Finder.ftp
: The URL scheme representing FTP connections.
Example Output:
After this command, Finder will manage FTP URLs entered in web browsers or other applications, directing them to open in Finder for browsing.
Use Case 4: Display Information About the Default Application for a Given Extension
Code:
duti -x ext
Motivation:
Understanding which application currently handles a particular file extension can be invaluable for troubleshooting and customization purposes, especially in a shared or multi-user environment where file associations might frequently change.
Explanation:
-x
: This flag is used to examine the current default application for a specified extension.ext
: Placeholder for the file extension you wish to inquire about (e.g.,pdf
for PDF files).
Example Output:
For instance, running duti -x pdf
could return:
com.adobe.Reader
Adobe Acrobat Reader DC
/Applications/Adobe Acrobat Reader DC.app
Use Case 5: Display the Default Handler for a Given UTI
Code:
duti -d uti
Motivation:
IT professionals and advanced users may need to confirm the default application responsible for a specific UTI to ensure compatibility and functionality within macOS. This helps in scenarios where documents do not open as expected.
Explanation:
-d
: Command option to display the current default handler.uti
: The UTI for which you want to find the associated default application.
Example Output:
If querying public.image
, you might see:
com.apple.Preview
Preview
/Applications/Preview.app
Use Case 6: Display All Handlers of a Given UTI
Code:
duti -l uti
Motivation:
When troubleshooting or customizing file handler settings, it’s often useful to know all possible applications that can handle a UTI. This is particularly helpful for users wanting to understand their options before setting a new default.
Explanation:
-l
: This flag lists all potential handlers for a given UTI.uti
: Refers to the UTI you want to explore.
Example Output:
Using public.jpeg
, the command might yield:
com.apple.Preview
com.adobe.Photoshop
org.videolan.vlc
Conclusion:
The duti
command provides macOS users with extensive control over their file handling experiences by allowing them to define and check default applications for various file types and protocols. Whether setting a preferred media player or finding handler information, duti
supports enhanced productivity and flexibility. By utilizing the command’s various options, users can tailor their system to fit their unique workflows and preferences.