Last active
March 11, 2023 17:37
-
-
Save fabjan/d192af2005b939123dc1acb7851e941e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Change the settings profile of all open Terminal.app windows to match the | |
# current system interface style (dark or light). By default, the "Pro" and | |
# "Novel" profiles are used for dark and light mode, respectively. You can | |
# override these defaults with the --dark and --light options. | |
# | |
# I use this to sync all my terminal windows with the automatic dark/light | |
# mode setting in macOS. | |
# | |
# Usage: | |
# match-terminal-app-theme-darkmode.sh [--dark <profile_name>] [--light <profile_name>] | |
# | |
# Usage with dark-mode-notify (https://github.com/bouk/dark-mode-notify): | |
# dark-mode-notify match-terminal-app-theme-darkmode.sh --dark "Gruvbox Dark" --light "Gruvbox Light" | |
# | |
# Or in a crontab hack if you don't have the build tools for dark-mode-notify: | |
# # Note: This runs every minute, but I don't think this is an issue. | |
# # Use dark-mode-notify if this feels too icky. | |
# * * * * * /Users/fabian/bin/match-terminal-app-theme-darkmode.sh --dark "Solarized Dark" --light "Solarized Light" | |
set -e | |
dark_profile_name="Pro" | |
light_profile_name="Novel" | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
--dark) | |
dark_profile_name="$2" | |
shift 2 | |
;; | |
--light) | |
light_profile_name="$2" | |
shift 2 | |
;; | |
*) | |
break | |
;; | |
esac | |
done | |
set +e | |
interface_style=$(defaults read -g AppleInterfaceStyle 2>/dev/null) | |
set -e | |
if [ "$interface_style" = "Dark" ]; then | |
profile_name="$dark_profile_name" | |
else | |
profile_name="$light_profile_name" | |
fi | |
current_profile_name=$(osascript -e "tell application \"Terminal\" to get name of default settings") | |
if [ "$current_profile_name" = "$profile_name" ]; then | |
exit 0 | |
fi | |
# reset default profile for any new windows that open | |
osascript -e "tell application \"Terminal\" to set default settings to settings set \"$profile_name\"" | |
# sync the profile of any open windows | |
osascript -e "tell application \"Terminal\" | |
repeat with w in windows | |
set current settings of w to settings set \"$profile_name\" | |
end repeat | |
end tell" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment