Inside a bash script, I need to know what the current OS X terminal theme is. How can this be done?
I check the output of the env command, but didn't find anything.
Inside a bash script, I need to know what the current OS X terminal theme is. How can this be done?
I check the output of the env command, but didn't find anything.
We can use an AppleScript to retrieve the name of the profile of the foremost Terminal window from within a bash shell:
echo 'tell application "Terminal" to return name of current settings of first window' | osascript
We can similarly set the profile:
echo 'tell application "Terminal" to set current settings of first window to settings set "Basic"' | osascript
Replace "Basic" with the name of the profile you wish to adopt.
These commands will apply to the current/foremost tab or window of Terminal.app
I've also written a script that will get/set the profile depending on whether a profile name is provided: https://github.com/starbase527/dotfiles/blob/master/local/bin/term-profile . Example usage:
# Gets profile name
> term-profile
Basic
# Sets profile to Basic
> term-profile Basic
>
Directly in zsh, you can get the current Terminal.app theme like this:
CURRENT_THEME=$(osascript -e 'tell application "Terminal" to return name of current settings of first window')
echo $CURRENT_THEME
From that, and with some AppleScript knowledge, you can get some of the details of the Terminal.app
Happy coding