Home > Management Profiles, Scripting > Deploying Terminal profile settings using macOS configuration profiles

Deploying Terminal profile settings using macOS configuration profiles

A number of Mac admins have their Terminal appearance settings configured just the way they like them, but it can be a bit of manual work to export and import them. After having to manually configure and export these settings more than a few times, I wanted to see if it was possible to export these settings in a way to make it easy to convert into a configuration profile.

With a little work and research, I was able to write a script which handled exporting the Terminal profile I wanted into a properly formatted plist file. For more details, please see below the jump.

The script I wrote is named Export_Mac_Terminal_Profiles and it is a .command file, which means it can be run by double-clicking on it. To use it, please use the following procedure:

  1. Identify the name of the Terminal profile you want to export.
  2. Double-click on the Export_Mac_Terminal_Profiles.command script.
  3. Enter the name of the Terminal profile you want to export.
  4. Decide if you want the exported Terminal profile to be set up as a default profile. By specifying it as a default profile, the exported Terminal profile will be configured as both a startup profile and as a default profile.

In this example, I’ve configured a custom Terminal profile named Documentation in my account’s Terminal settings and want to export it for use with a configuration profile.

Screen Shot 2019 12 18 at 4 47 23 PM

To export it, I followed the procedure described above and entered the following when prompted:

Name: Documentation
Default profile: 1 (which configures the exported profile to be set as both a startup profile and as a default profile.)

Screen Shot 2019 12 18 at 6 16 55 PM

When the script finished running, it opened a Finder window showing me a com.apple.Terminal.plist file.

Screen Shot 2019 12 18 at 6 16 35 PM

This plist file contained all of the settings needed to create a configuration profile which did the following:

  1. Install the Documentation Terminal profile
  2. Configure the Documentation Terminal profile as both a startup profile and as a default profile.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
<plist version="1.0">
<dict>
<key>Default Window Settings</key>
<string>Documentation</string>
<key>Startup Window Settings</key>
<string>Documentation</string>
<key>Window Settings</key>
<dict>
<key>Documentation</key>
<dict>
<key>Font</key>
<data>
YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0
b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRy
b290gAGkCwwVFlUkbnVsbNQNDg8QERITFFZOU1NpemVYTlNmRmxh
Z3NWTlNOYW1lViRjbGFzcyNAMgAAAAAAABAQgAKAA1ZNb25hY2/S
FxgZGlokY2xhc3NuYW1lWCRjbGFzc2VzVk5TRm9udKIZG1hOU09i
amVjdAgRGiQpMjdJTFFTWF5nbnd+hY6QkpSboKu0u74AAAAAAAAB
AQAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAxw==
</data>
<key>FontAntialias</key>
<true/>
<key>FontWidthSpacing</key>
<real>1.004032258064516</real>
<key>Linewrap</key>
<true/>
<key>ProfileCurrentVersion</key>
<real>2.0699999999999998</real>
<key>name</key>
<string>Documentation</string>
<key>type</key>
<string>Window Settings</string>
</dict>
</dict>
</dict>
</plist>

From there, I used Tim Sutton‘s mcxToProfile tool to create a configuration profile from the exported com.apple.Terminal.plist file.

Screen Shot 2019 12 18 at 6 25 47 PM

Once I had the configuration profile, I verified that I was able to install it and that the Documentation Terminal profile was now installed and set as the default profile.

Screen Shot 2019 12 18 at 5 10 07 PM

However, one side effect I noticed was that installing a Terminal profile using a configuration profile resulted in all other Terminal profiles vanishing from the Terminal preferences.

Screen Shot 2019 12 18 at 4 42 25 PM

To restore copies of the OS-provided Terminal profiles, click on the Profiles window’s cog wheel and select Restore Default Profiles.

Screen Shot 2019 12 18 at 4 44 49 PM

This will restore the OS-installed Terminal profiles in their default configuration. This restore process will not affect the Terminal profile installed by the configuration profile.

Screen Shot 2019 12 18 at 4 47 23 PM

The Export_Mac_Terminal_Profiles script is available below and also on GitHub at the following address:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/Export_Mac_Terminal_Profiles


#!/bin/bash
exported_theme_file=$(mktemp)
exported_temp_directory=$(mktemp -d -t terminal-theme-XXXXXXXXXX)
import_plist_file="$HOME/Library/Preferences/com.apple.Terminal.plist"
export_plist_file="$exported_temp_directory/com.apple.Terminal.plist"
IFS= read -r -p "Enter name of the Terminal profile to export from your Terminal settings: " terminal_profile_name
echo "Do you want to set the exported Terminal profile as being a default Terminal profile?"
select yn in "Yes" "No"; do
case $yn in
Yes) /usr/bin/defaults write "$export_plist_file" "Default Window Settings" -string "${terminal_profile_name}"; /usr/bin/defaults write "$export_plist_file" "Startup Window Settings" -string "${terminal_profile_name}"; echo "Exported Terminal profile is set as a default Terminal profile."; break;;
No ) echo "Exported Terminal profile will not be set as a default Terminal profile."; break;;
esac
done
/usr/bin/plutil -extract Window\ Settings."${terminal_profile_name}" xml1 -o – "$import_plist_file" > "$exported_theme_file"
import_theme=$(<"$exported_theme_file")
/usr/bin/defaults write "$export_plist_file" "Window Settings" -dict
/usr/bin/plutil -replace Window\ Settings."${terminal_profile_name}" -xml "$import_theme" "$export_plist_file"
/usr/bin/plutil -convert xml1 "$export_plist_file"
echo "Exported com.apple.Terminal.plist is available at the following location: $export_plist_file"
open "$exported_temp_directory"

The example configuration profile for the Documentation Terminal profile is also available below.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadContent</key>
<dict>
<key>com.apple.Terminal</key>
<dict>
<key>Forced</key>
<array>
<dict>
<key>mcx_preference_settings</key>
<dict>
<key>Default Window Settings</key>
<string>Documentation</string>
<key>Startup Window Settings</key>
<string>Documentation</string>
<key>Window Settings</key>
<dict>
<key>Documentation</key>
<dict>
<key>Font</key>
<data>
YnBsaXN0MDDU
AQIDBAUGBwpY
JHZlcnNpb25Z
JGFyY2hpdmVy
VCR0b3BYJG9i
amVjdHMSAAGG
oF8QD05TS2V5
ZWRBcmNoaXZl
ctEICVRyb290
gAGkCwwVFlUk
bnVsbNQNDg8Q
ERITFFZOU1Np
emVYTlNmRmxh
Z3NWTlNOYW1l
ViRjbGFzcyNA
MgAAAAAAABAQ
gAKAA1ZNb25h
Y2/SFxgZGlok
Y2xhc3NuYW1l
WCRjbGFzc2Vz
Vk5TRm9udKIZ
G1hOU09iamVj
dAgRGiQpMjdJ
TFFTWF5nbnd+
hY6QkpSboKu0
u74AAAAAAAAB
AQAAAAAAAAAc
AAAAAAAAAAAA
AAAAAAAAxw==
</data>
<key>FontAntialias</key>
<true/>
<key>FontWidthSpacing</key>
<real>1.004032258064516</real>
<key>Linewrap</key>
<true/>
<key>ProfileCurrentVersion</key>
<real>2.0699999999999998</real>
<key>name</key>
<string>Documentation</string>
<key>type</key>
<string>Window Settings</string>
</dict>
</dict>
</dict>
</dict>
</array>
</dict>
</dict>
<key>PayloadEnabled</key>
<true/>
<key>PayloadIdentifier</key>
<string>MCXToProfile.2548385c-4378-49c0-84ed-c454fcf9e50b.alacarte.customsettings.c8a7ea9d-8e7d-4f29-87f0-8604fc377761</string>
<key>PayloadType</key>
<string>com.apple.ManagedClient.preferences</string>
<key>PayloadUUID</key>
<string>c8a7ea9d-8e7d-4f29-87f0-8604fc377761</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</array>
<key>PayloadDescription</key>
<string>This profile installs the Documentation Terminal profile and sets it as the default Terminal profile.</string>
<key>PayloadDisplayName</key>
<string>Sets Documentation Terminal profile</string>
<key>PayloadIdentifier</key>
<string>com.company.terminal.profile.settings.Documentation</string>
<key>PayloadOrganization</key>
<string>Company Name</string>
<key>PayloadRemovalDisallowed</key>
<true/>
<key>PayloadScope</key>
<string>System</string>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>2548385c-4378-49c0-84ed-c454fcf9e50b</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment