FelixKratz / SketchyBar

A highly customizable macOS status bar replacement
https://felixkratz.github.io/SketchyBar/
GNU General Public License v3.0
6.67k stars 97 forks source link

$INFO output with hidden bar #446

Closed PhrantiK closed 1 year ago

PhrantiK commented 1 year ago

Trying to figure out the best way to hide a bar for a specific space. Noticed we can do it by display (#42) and also saw another issue with a bunch of yabai signals (https://github.com/FelixKratz/SketchyBar/issues/175#issuecomment-1084409282).

Is it possible to do it with an item & space_change event to keep things a bit faster & leaner?

ITEM:

sketchybar --add item hide2 right \
            --set hide2 script="$PLUGIN_DIR/hide2.sh" \
            --subscribe hide2 space_change

PLUGIN:

hide() {
  # sketchybar --bar hidden=on
  echo "turn it off"
}

unhide() {
  # sketchybar --bar hidden=off
  echo "turn it on"
}

case $(echo "$INFO" | jq '.[]') in
  "2") hide
  ;;
  *) unhide
  ;;
esac

It works great but when the bar is hidden, $INFO stops outputting so the bar stays hidden. Not sure if that's by design, a bug or feature request. Thanks!

FelixKratz commented 1 year ago

This will work perfectly if you set sketchybar --set hide2 updates=on because I presume it is currently set to when_shown, hence it will not call its script when the item is not drawn to screen.

PhrantiK commented 1 year ago

PEBKAC - Thanks Felix!

Edit: Leaving this here for posterity.

Been mucking about with the helper program to do this instead of adding an item and got it working:

add mach_helper=$HELPER to the spaces config and add this to the helper:

  else if (strcmp(sender, "space_change") == 0) {
    // turn the bar off on D1S2
    char *dos = strstr(info, "{\n\t\"display-1\": 2\n}");
    char command[256];
    char *hide;

    hide = dos ? "on" : "off";

    snprintf(command, 256, "--bar hidden=%s", hide);
    sketchybar(command);
  }

Makes it instant. Thanks again for the awesome software!