5

So I have many profiles in my terminal preference, as shown below

profile

I would like to be able to change the font for all of these different profiles at once

3024 Day, 3024 Night, AdventureTime...

Right now I have to make such change one by one, how do I change the font once and for all?

Please let me know if it is not clear enough of what I am trying to do. Thanks in advance!

3 Answers 3

6

Very easy with an AppleScript code (here an example where all profiles are set to Menlo Regular 18 pt, note that "Menlo Regular" is named "Menlo-Regular" in font name):

tell application "Terminal"
    set ProfilesNames to name of every settings set
    repeat with ProfileName in ProfilesNames
        set font name of settings set ProfileName to "Menlo-Regular"
        set font size of settings set ProfileName to 18
    end repeat
end tell
4
  • Your answer has been really helpful. But how did you find out the correct names of the key words? I am asking this because I want to change the cursor to vertical bar for all themes. Thanks!
    – zyy
    Apr 11, 2019 at 1:48
  • 1
    @zyy In the Script Editor app, go to the menu File > Open Dictionary, and choose the Terminal app in the list. In the "Terminal Suite" you will see the command "setting set" and here the properties you can change. Unfortunately, there is nothing for choose between Block cursor and Vertical Bar cursor. In these case, the other solution is to use GUI scripting with AppleScript, in order to simulate clicks on check box and buttons of the interface. Or open the preference file .plist from Alex answer, and search or add the key CursorType for all dict entry, and set <integer>2</integer>.
    – quark67
    Apr 11, 2019 at 2:35
  • this language hurts my head... how do I set just a specific profile? Nov 8, 2023 at 19:07
  • @xenoterracide if you like to set font name and size of the profile "Solid Colors" to "Menlo-Regular" and 18pt, use only this code: tell application "Terminal" to set {font name of settings set "Solid Colors", font size of settings set "Solid Colors"} to {"Menlo-Regular", 18}.
    – quark67
    Nov 9, 2023 at 22:20
1

I think this will work, but you might need to test it. I'd say you need to be comfortable with the Terminal, but given the question, I'll skip right over it.

Terminal configuration is stored in a property list file in ~/Library/Preferences/com.apple.Terminal.plist in a binary format.

Each profile is stored in a dictionary, and has a Font key within it. You want to extract the Font key from a good profile, and copy/paste into all the others. Or, find/replace if you're using an editor with a regex replace. For example, for the Basic profile, I have:

    <dict>
    <key>Basic</key>
    <dict>
        <key>Font</key>
        <data>
        YnBsaXN0MDDUAQIDBAUGGBlYJHZlcnNpb25YJG9iamVjdHNZJGFy
        Y2hpdmVyVCR0b3ASAAGGoKQHCBESVSRudWxs1AkKCwwNDg8QVk5T
        U2l6ZVhOU2ZGbGFnc1ZOU05hbWVWJGNsYXNzI0AmAAAAAAAAEBCA
        AoADXlNGTW9uby1SZWd1bGFy0hMUFRZaJGNsYXNzbmFtZVgkY2xh
        c3Nlc1ZOU0ZvbnSiFRdYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
        ZXLRGhtUcm9vdIABCBEaIy0yNzxCS1JbYmlydHZ4h4yXoKeqs8XI
        zQAAAAAAAAEBAAAAAAAAABwAAAAAAAAAAAAAAAAAAADP
        </data>
        <key>FontAntialias</key>
        <true/>
        <key>FontWidthSpacing</key>
        <real>1.004032258064516</real>
        <key>ProfileCurrentVersion</key>
        <real>2.0600000000000001</real>
        <key>name</key>
        <string>Basic</string>
        <key>type</key>
        <string>Window Settings</string>
    </dict>

You want to copy the whole Font key and data blocks between each of your profiles.

Steps:

  1. Close Terminal.

  2. Back up your original prefs:

    cp ~/Library/Preferences/com.apple.Terminal.plist ~/Desktop/com.apple.Terminal.plist.bak
    
  3. Convert your working copy to XML:

    cd ~/Library/Preferences
    plutil -convert xml1 com.apple.Terminal.plist
    
  4. Edit the file and copy/paste the font data blocks into all the profiles. I used TextMate, but any text edit will work.

  5. Save it, and convert it back to binary:

    plutil -convert binary1 com.apple.Terminal.plist
    
  6. Test Terminal.

The Font block controls the font choice and size. If you also want to replicate colours and text options (antialias, etc), then you'll need to copy/paste those blocks across too.

2
  • I made some edits; however, the order of your steps is wrong. If your first close Terminal, then how are you going to run the commands in the other steps! Also, you only need to use 1. for each step and they'll auto number correctly, which makes it easier to move/add/remove the steps when edits are needed. Feb 25, 2019 at 4:27
  • Ah, good point. I actually use iTerm2, this was the first time firing up Terminal in a while, and during testing I noticed that on save it writes back the prefs. Regardless, goal is easily accomplished with the steps provided.
    – Alex
    Feb 25, 2019 at 14:21
0

You can use the instructions that @Alex posted above to extract the Font <data/> element into an XML file. I called mine font.xml and then use the putil command to load it into the profiles you are interested in updating.

  1. cp ~/Library/Preferences/com.apple.Terminal.plist ~/Desktop/
  2. Convert your working copy to XML:
    cd ~/Desktop
    plutil -convert xml1 com.apple.Terminal.plist
    
  3. Open the file in a text editor and find the font you want to use from the profile.
    <dict>
     <key>Basic</key>
     <dict>
         <key>Font</key>
         <data>
         YnBsaXN0MDDUAQIDBAUGGBlYJHZlcnNpb25YJG9iamVjdHNZJGFy
         Y2hpdmVyVCR0b3ASAAGGoKQHCBESVSRudWxs1AkKCwwNDg8QVk5T
         U2l6ZVhOU2ZGbGFnc1ZOU05hbWVWJGNsYXNzI0AmAAAAAAAAEBCA
         AoADXlNGTW9uby1SZWd1bGFy0hMUFRZaJGNsYXNzbmFtZVgkY2xh
         c3Nlc1ZOU0ZvbnSiFRdYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
         ZXLRGhtUcm9vdIABCBEaIy0yNzxCS1JbYmlydHZ4h4yXoKeqs8XI
         zQAAAAAAAAEBAAAAAAAAABwAAAAAAAAAAAAAAAAAAADP
         </data>
         <key>FontAntialias</key>
         <true/>
         <key>FontWidthSpacing</key>
         <real>1.004032258064516</real>
         <key>ProfileCurrentVersion</key>
         <real>2.0600000000000001</real>
         <key>name</key>
         <string>Basic</string>
         <key>type</key>
         <string>Window Settings</string>
     </dict>
    
  4. Copy the <data/> element into an XML file.
    <data>
         YnBsaXN0MDDUAQIDBAUGGBlYJHZlcnNpb25YJG9iamVjdHNZJGFy
         Y2hpdmVyVCR0b3ASAAGGoKQHCBESVSRudWxs1AkKCwwNDg8QVk5T
         U2l6ZVhOU2ZGbGFnc1ZOU05hbWVWJGNsYXNzI0AmAAAAAAAAEBCA
         AoADXlNGTW9uby1SZWd1bGFy0hMUFRZaJGNsYXNzbmFtZVgkY2xh
         c3Nlc1ZOU0ZvbnSiFRdYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
         ZXLRGhtUcm9vdIABCBEaIy0yNzxCS1JbYmlydHZ4h4yXoKeqs8XI
         zQAAAAAAAAEBAAAAAAAAABwAAAAAAAAAAAAAAAAAAADP
    </data>
    
  5. In a terminal run the following replacing the <YOUR PROFILE NAME> with the name of the profile to update.
    font=$(<./font.xml)
    plutil -replace  Window\ Settings.<YOUR PROFILE NAME>.Font -xml "$font" ~/Library/Preferences/com.apple.Terminal.plist
    
  6. Restart Terminal and check the Terminal settings and terminal for the new font.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .