<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nick Ficano</title>
    <description>The latest articles on Forem by Nick Ficano (@nficano).</description>
    <link>https://forem.com/nficano</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1106700%2F6898b2ba-711b-4308-b78d-c52e025edae9.jpeg</url>
      <title>Forem: Nick Ficano</title>
      <link>https://forem.com/nficano</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nficano"/>
    <language>en</language>
    <item>
      <title>Harnessing The Power of Duti: Command-Line Customization of Default File Opener in MacOS</title>
      <dc:creator>Nick Ficano</dc:creator>
      <pubDate>Thu, 22 Jun 2023 23:35:47 +0000</pubDate>
      <link>https://forem.com/nficano/harnessing-the-power-of-duti-command-line-customization-of-default-file-opener-in-macos-12kk</link>
      <guid>https://forem.com/nficano/harnessing-the-power-of-duti-command-line-customization-of-default-file-opener-in-macos-12kk</guid>
      <description>&lt;p&gt;I always found it super irritating that MacOS makes setting up default file associations such a manual process. Then I discovered &lt;code&gt;duti&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;duti&lt;/code&gt; is a command-line utility that allows you to define the default file opener for any file type. You can set your favorite text editor to open code files, have PDFs open in your preferred viewer, and assign specific applications to open different image file types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Duti
&lt;/h2&gt;

&lt;p&gt;Before using &lt;code&gt;duti&lt;/code&gt;, you need to install it. The simplest way to install &lt;code&gt;duti&lt;/code&gt; on your Mac is via Homebrew. If you haven't installed Homebrew yet, you can install it with this command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/bin/bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once Homebrew is installed, you can install &lt;code&gt;duti&lt;/code&gt; with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;duti
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Duti to Set Default Applications
&lt;/h2&gt;

&lt;p&gt;The basic syntax of the &lt;code&gt;duti&lt;/code&gt; command is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;duti &lt;span class="nt"&gt;-s&lt;/span&gt; com.example.MyApp myextension all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;com.example.MyApp&lt;/code&gt; is the bundle identifier of the application you want to set as the default, &lt;code&gt;myextension&lt;/code&gt; is the file extension you want to change the default for, and &lt;code&gt;all&lt;/code&gt; is the role (which can be 'all', 'editor', or 'viewer').&lt;/p&gt;

&lt;p&gt;To find the bundle identifier of an application, you can use the following command, replacing &lt;code&gt;AppName&lt;/code&gt; with the name of the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;osascript &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'id of app "AppName"'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, to set Visual Studio Code as the default application for .txt files, you would first get Visual Studio Code's bundle identifier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;osascript &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'id of app "Visual Studio Code"'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will output something like &lt;code&gt;com.microsoft.VSCode&lt;/code&gt;. You can then set Visual Studio Code as the default for .txt files with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;duti &lt;span class="nt"&gt;-s&lt;/span&gt; com.microsoft.VSCode txt all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Verifying Changes with Duti
&lt;/h2&gt;

&lt;p&gt;To verify your changes, you can use the &lt;code&gt;-x&lt;/code&gt; flag followed by the extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;duti &lt;span class="nt"&gt;-x&lt;/span&gt; txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should return something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/Volumes/Macintosh HD/Applications/Visual Studio Code.app
com.microsoft.VSCode
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This confirms that Visual Studio Code is now the default application for .txt files.&lt;/p&gt;

</description>
      <category>macos</category>
      <category>shell</category>
      <category>dotfiles</category>
    </item>
  </channel>
</rss>
