Closed rogeruiz closed 10 months ago
I think it might have been removed by apple in a recent software update. I might look into adding a native event for theme change by observing the appkit effectiveAppearance field from the C side.
This is the config I have tested this with:
#!/bin/sh
sketchybar --bar color=0xff000000 \
--add event theme_change AppleInterfaceThemeChangedNotification \
--add item theme left \
--set theme script="echo 'Event'" \
--subscribe theme theme_change
other notifications still work fine, e.g. AppleInterfaceMenuBarHidingChangedNotification
I think it might have been removed by apple in a recent software update.
Aha! This was my best guess but wanted to exhaust all the other options first. I wish it were more documented but I guess that's what I get for heavily relying on undocumented Apple APIs. Thanks @FelixKratz.
For now I'll manually change things, but I look forward to an update in the future with a custom event. I also have some free time and may look into the code for this. Could you point me to the files that would need to be changed to add this?
It should work again in v.2.16.4, it seems this was a problem due to some recent changes I made to the run loop of the app.
hi @FelixKratz I've been trying to get it working again by uninstalling and reinstalling the new version and restarting my machine. I'm still not seeing the AppleInterfaceThemeChangedNotification
event getting triggered on my machine. Here's a video of it attached. I'm currently on version 2.16.4 via Homebrew. I am on macOS 14.0 still as well.
Try this sketchybarrc:
#!/bin/bash
bar=(
height=30
color=0xff000000
position=top
sticky=on
)
sketchybar --bar "${bar[@]}"
sketchybar --add event theme_change AppleInterfaceThemeChangedNotification
sketchybar --add item theme left \
--set theme script="osascript -e 'display notification \"Theme Changed\" with title \"Note\"'" \
--subscribe theme theme_change
echo "sketchybar configuration loaded.."
It should work fine. I think there is a problem in the theme item that you posted above:
You have set updates=when_shown
as a default and set drawing=off
for the theme item. This means that the script is not executed even when an event occurs. You would have to explicitly set updates=on
for the theme item, such that it receives events even though it is not rendered to screen. Might that be why you are not seeing it working?
ah perfect! thank you so much @FelixKratz that cleared the issue up. I appreciate your time looking into this for me. 💯
I'm experiencing some issues using
AppleInterfaceThemeChangedNotification
on macOS 13.5.2. I'm currently using versionv2.16.3
. I have a minimal reproduction config and script that I call outlined below.Contents of
```sh #!/usr/bin/env bash # vim:fdm=marker # shellcheck disable=SC2034 # these warnings are irrelevant for this script # color definitions {{{ # mocha {{{ mocha_rosewater="f5e0dc" mocha_flamingo="f2cdcd" mocha_pink="f5c2e7" mocha_mauve="cba6f7" mocha_red="f38ba8" mocha_maroon="eba0ac" mocha_peach="fab387" mocha_yellow="f9e2af" mocha_green="a6e3a1" mocha_teal="94e2d5" mocha_sky="89dceb" mocha_sapphire="74c7ec" mocha_blue="89b4fa" mocha_lavender="b4befe" mocha_text="cdd6f4" mocha_subtext1="bac2de" mocha_subtext0="a6adc8" mocha_overlay2="9399b2" mocha_overlay1="7f849c" mocha_overlay0="6c7086" mocha_surface2="585b70" mocha_surface1="45475a" mocha_surface0="313244" mocha_base="1e1e2e" mocha_mantle="181825" mocha_crust="11111b" ## }}} ## macchiato {{{ macchiato_rosewater="f4dbd6" macchiato_flamingo="f0c6c6" macchiato_pink="f5bde6" macchiato_mauve="c6a0f6" macchiato_red="ed8796" macchiato_maroon="ee99a0" macchiato_peach="f5a97f" macchiato_yellow="eed49f" macchiato_green="a6da95" macchiato_teal="8bd5ca" macchiato_sky="91d7e3" macchiato_sapphire="7dc4e4" macchiato_blue="8aadf4" macchiato_lavender="b7bdf8" macchiato_text="cad3f5" macchiato_subtext1="b8c0e0" macchiato_subtext0="a5adcb" macchiato_overlay2="939ab7" macchiato_overlay1="8087a2" macchiato_overlay0="6e738d" macchiato_surface2="5b6078" macchiato_surface1="494d64" macchiato_surface0="363a4f" macchiato_base="24273a" macchiato_mantle="1e2030" macchiato_crust="181926" ## }}} # frappe {{{ frappe_rosewater="f2d5cf" frappe_flamingo="eebebe" frappe_pink="f4b8e4" frappe_mauve="ca9ee6" frappe_red="e78284" frappe_maroon="ea999c" frappe_peach="ef9f76" frappe_yellow="e5c890" frappe_green="a6d189" frappe_teal="81c8be" frappe_sky="99d1db" frappe_sapphire="85c1dc" frappe_blue="8caaee" frappe_lavender="babbf1" frappe_text="c6d0f5" frappe_subtext1="b5bfe2" frappe_subtext0="a5adce" frappe_overlay2="949cbb" frappe_overlay1="838ba7" frappe_overlay0="737994" frappe_surface2="626880" frappe_surface1="51576d" frappe_surface0="414559" frappe_base="303446" frappe_mantle="292c3c" frappe_crust="232634" ## }}} ## latte {{{ latte_rosewater="dc8a78" latte_flamingo="dd7878" latte_pink="ea76cb" latte_mauve="8839ef" latte_red="d20f39" latte_maroon="e64553" latte_peach="fe640b" latte_yellow="df8e1d" latte_green="40a02b" latte_teal="179299" latte_sky="04a5e5" latte_sapphire="209fb5" latte_blue="1e66f5" latte_lavender="7287fd" latte_text="4c4f69" latte_subtext1="5c5f77" latte_subtext0="6c6f85" latte_overlay2="7c7f93" latte_overlay1="8c8fa1" latte_overlay0="9ca0b0" latte_surface2="acb0be" latte_surface1="bcc0cc" latte_surface0="ccd0da" latte_crust="dce0e8" latte_mantle="e6e9ef" latte_base="eff2f5" ## }}} # }}} LIGHT_THEME="latte" DARK_THEME="mocha" # check wether or not macOS is in dark mode if defaults read -g AppleInterfaceStyle &>/dev/null then theme=$DARK_THEME else theme=$LIGHT_THEME fi function color() { alpha=${2:-255} color="$1" printf -v alpha "%02x" "$alpha" selected_color="${theme}_${color}" echo "0x${alpha}${!selected_color}" } sketchybar \ --bar \ color="$(color base)" \ --default \ icon.color="$(color subtext0)" \ label.color="$(color subtext1)" \ --set /space\./ \ icon.color="$(color mauve)" \ icon.highlight_color="$(color green)" \ --set front_app \ background.color="$(color green)" \ icon.color="$(color mantle)" \ label.color="$(color mantle)" \ --set music \ background.color="$(color mauve)" \ label.color="$(color crust)" \ --set mic \ background.color="$(color base)" \ icon.color="$(color red)" \ icon.highlight_color="$(color green)" \ --set sound \ background.color="$(color crust)" \ icon.color="$(color green)" \ label.color="$(color subtext1)" \ icon.highlight_color="$(color red)" \ label.highlight_color="$(color red)" \ --set headphones \ background.color="$(color crust)" \ icon.color="$(color sapphire)" \ label.color="$(color subtext1)" \ --set wifi \ background.color="$(color mantle)" \ icon.color="$(color flamingo)" \ label.color="$(color subtext1)" \ --set battery \ background.color="$(color crust)" \ label.color="$(color subtext0)" \ --set clock \ icon.color="$(color mauve)" \ label.color="$(color subtext0)" \ ~/.local/bin/darwin/current_visual_mode # set the yabai colours as well yabai \ -m config active_window_border_color "$(color pink)" \ -m config normal_window_border_color "$(color mauve)" \ -m config feedback_color "$(color pink)" ```set_theme.sh
I have tried the following things to troubleshoot the issue myself.
sketchybar
manually to see if there were any errors pertaining the the script. There were none.set_theme.sh
manually. There were only errors related to theyabai
commands. This seems unrelated tosketchybar
.~/.sketchybarrc
config except for the theme changes and the issue still persisted.drawing=off
todrawing=on
to see if this had any affect and it still was unresponsive.current_visual_mode
called from theset_theme.sh
script, and it runs properly.sketchybar
set to on in the System Preferences under Automation, Screen Recording, and Accessibility.sketchybar
using Homebrew.The expected behavior here for me is that I want
sketchybar
to run theset_theme.sh
script wheneverAppleInterfaceThemeChangedNotification
is fired.Thanks so much for building this tool and taking the time to read this. I am open to trying out other things to troubleshoot if needed as well.