@@ -7,28 +7,28 @@ mkdir -p "$(dirname "$LOG_FILE")"
77timestamp () { date +" %Y-%m-%d %H:%M:%S" ; }
88
99is_dark () {
10- # Prefer AppleScript for reliable detection on modern macOS
11- if osascript -e ' tell application "System Events" to tell appearance preferences to get dark mode' \
12- 2> /dev/null | grep -qi true ; then
13- return 0
14- fi
15- # Fallback to defaults key
16- defaults read -g AppleInterfaceStyle 2> /dev/null | grep -qi " Dark"
10+ # Prefer AppleScript for reliable detection on modern macOS
11+ if osascript -e ' tell application "System Events" to tell appearance preferences to get dark mode' \
12+ 2> /dev/null | grep -qi true ; then
13+ return 0
14+ fi
15+ # Fallback to defaults key
16+ defaults read -g AppleInterfaceStyle 2> /dev/null | grep -qi " Dark"
1717}
1818
1919# Allow overriding theme with first argument: 'light' or 'dark'
2020THEME_OVERRIDE=${1:- }
2121case " $THEME_OVERRIDE " in
22- light| dark)
23- THEME=" $THEME_OVERRIDE "
24- ;;
25- * )
26- if is_dark; then
27- THEME=" dark"
28- else
29- THEME=" light"
30- fi
31- ;;
22+ light | dark)
23+ THEME=" $THEME_OVERRIDE "
24+ ;;
25+ * )
26+ if is_dark; then
27+ THEME=" dark"
28+ else
29+ THEME=" light"
30+ fi
31+ ;;
3232esac
3333
3434# Ensure PATH includes Homebrew bin for launchd context
@@ -41,51 +41,49 @@ KITTY_THEME_LINK="$HOME/.config/kitty/theme.conf"
4141
4242# Ensure the kitty startup include points to the current theme
4343if [ " $THEME " = " dark" ] && [ -f " $KITTY_THEME_DARK " ]; then
44- ln -sf " $KITTY_THEME_DARK " " $KITTY_THEME_LINK "
44+ ln -sf " $KITTY_THEME_DARK " " $KITTY_THEME_LINK "
4545elif [ " $THEME " = " light" ] && [ -f " $KITTY_THEME_LIGHT " ]; then
46- ln -sf " $KITTY_THEME_LIGHT " " $KITTY_THEME_LINK "
46+ ln -sf " $KITTY_THEME_LIGHT " " $KITTY_THEME_LINK "
4747fi
4848
4949PREV_THEME=" "
5050if [ -f " $HOME /.theme" ]; then
51- PREV_THEME=$( cat " $HOME /.theme" 2> /dev/null || true)
51+ PREV_THEME=$( cat " $HOME /.theme" 2> /dev/null || true)
5252fi
5353
5454if [ " $THEME " != " $PREV_THEME " ]; then
55- echo " $( timestamp) Theme detected: $THEME " >> " $LOG_FILE "
56- echo " $THEME " > " $HOME /.theme"
55+ echo " $( timestamp) Theme detected: $THEME " >> " $LOG_FILE "
56+ echo " $THEME " > " $HOME /.theme"
5757fi
5858
5959# Notify sketchybar if available
6060if command -v sketchybar > /dev/null 2>&1 ; then
61- if pgrep -x sketchybar > /dev/null 2>&1 ; then
62- # Try to trigger a custom event first; fall back to reload
63- sketchybar --trigger theme_change THEME=" $THEME " > /dev/null 2>&1 || \
64- sketchybar --reload > /dev/null 2>&1 || true
65- fi
61+ if pgrep -x sketchybar > /dev/null 2>&1 ; then
62+ # Try to trigger a custom event first; fall back to reload
63+ sketchybar --trigger theme_change THEME=" $THEME " > /dev/null 2>&1 ||
64+ sketchybar --reload > /dev/null 2>&1 || true
65+ fi
6666fi
6767
6868# Try to update kitty colors if remote control is available and theme files exist
6969if command -v kitty > /dev/null 2>&1 ; then
70- # Prefer fixed socket if configured to avoid controlling-terminal limitations
71- if [ -S /tmp/kitty ]; then
72- KITTYCTL=(kitty @ --to unix:/tmp/kitty)
73- else
74- KITTYCTL=(kitty @)
75- fi
76- # Apply to all running kitty windows regardless of change to enforce state
77- if [ " $THEME " = " dark" ] && [ -f " $KITTY_THEME_DARK " ]; then
78- " ${KITTYCTL[@]} " set-colors --all --configured " $KITTY_THEME_DARK " > /dev/null 2>&1 || true
79- elif [ " $THEME " = " light" ] && [ -f " $KITTY_THEME_LIGHT " ]; then
80- " ${KITTYCTL[@]} " set-colors --all --configured " $KITTY_THEME_LIGHT " > /dev/null 2>&1 || true
81- fi
70+ # Prefer fixed socket if configured to avoid controlling-terminal limitations
71+ if [ -S /tmp/kitty ]; then
72+ KITTYCTL=(kitty @ --to unix:/tmp/kitty)
73+ else
74+ KITTYCTL=(kitty @)
75+ fi
76+ # Apply to all running kitty windows regardless of change to enforce state
77+ if [ " $THEME " = " dark" ] && [ -f " $KITTY_THEME_DARK " ]; then
78+ " ${KITTYCTL[@]} " set-colors --all --configured " $KITTY_THEME_DARK " > /dev/null 2>&1 || true
79+ elif [ " $THEME " = " light" ] && [ -f " $KITTY_THEME_LIGHT " ]; then
80+ " ${KITTYCTL[@]} " set-colors --all --configured " $KITTY_THEME_LIGHT " > /dev/null 2>&1 || true
81+ fi
8282fi
8383
8484# Optional user hook for further customization
8585if [ -x " $HOME /scripts/on_theme_change.sh" ]; then
86- " $HOME /scripts/on_theme_change.sh" " $THEME " >> " $LOG_FILE " 2>&1 || true
86+ " $HOME /scripts/on_theme_change.sh" " $THEME " >> " $LOG_FILE " 2>&1 || true
8787fi
8888
8989exit 0
90-
91-
0 commit comments