Skip to main content

A tiny lib for Sketchybar configuring with Python

Project description

sketchybar-py

A Python library for configuring SketchyBar - a highly customizable macOS status bar replacement. This library allows you to configure your SketchyBar using Python instead of traditional bash scripting, making the configuration process more intuitive and maintainable.

Features

  • Configure SketchyBar using Python syntax instead of bash
  • Define bar items as functions, combining creation and behavior in one place
  • More structured and maintainable configuration approach
  • Native Python integration with SketchyBar's functionality
  • No external dependencies

Prerequisites

Installation

Option 1: Using uv (Recommended)

Add the following shebang declaration to the top of your script:

#!/usr/bin/env -S uv run -q
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "sketchybar_py @ git+https://github.com/dimentium/sketchybar-py",
# ]
# ///

Option 2: Direct Import

Copy src/sketchybar_py/__init__.py to your sketchybar config directory and import directly.

Usage

Add the following line to your sketchybarrc:

$CONFIG_DIR/sketchybar.py

Make the Python configuration file executable:

chmod +x sketchybar.py

Example

Here's a complete example of sketchybar.py showing how to configure SketchyBar using sketchybar-py (with uv):

#!/usr/bin/env -S uv run -q
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "sketchybar_py @ git+https://github.com/dimentium/sketchybar-py",
# ]
# ///

from sketchybar_py import Sketchybar

global_bar_properties = {
    "position": "top",
    "height": "24",
    "blur_radius": "0",
    "color": "0x44444444",
}

default_settings_for_new_items = {
    "padding_left": 5,
    "padding_right": 5,
    "icon.font": "FiraCode Nerd Font:Bold:12.0",
    "label.font": "FiraCode Nerd Font:Bold:12.0",
    "icon.color": "0xffffffff",
    "label.color": "0xffffffff",
    "icon.padding_left": 4,
    "icon.padding_right": 4,
    "label.padding_left": 4,
    "label.padding_right": 4,
}


class MyAwesomeSketchyBar(Sketchybar):
    def post_init(self):
        print("Init...")
        self.do("--bar", global_bar_properties)
        self.do("--default", default_settings_for_new_items)
        self.do("--hotload", "true")
        self.autoload()

    @Sketchybar.item(
        position="left",
        icon="",
        properties={"label.drawing": "off"}
    )
    def l0_chevron(self):
        pass

    @Sketchybar.item(
        position="left",
        icon="++",
        subscribe=["front_app_switched"],
        properties={"icon.drawing": "off"},
    )
    def l1_front_app(self):
        if self.sender == "front_app_switched":
            self.label = self.info

    @Sketchybar.item(
        position="right",
        update_freq=60,
        subscribe=["system_woke", "power_source_change"],
    )
    def r2_battery(self):
        percentage = (
            self.run("pmset -g batt | grep -Eo '\\d+%'").stdout.strip().rstrip("%")
        )
        charging = "AC Power" in self.run("pmset -g batt").stdout
        self.icon = "" if charging else "󱟟"
        self.label = percentage + "%"

    @Sketchybar.item(
        position="right", 
        update_freq=10, 
        properties={"icon.drawing": "off"}
    )
    def r1_clock(self):
        now = self.run("date '+%d/%m %H:%M'").stdout
        self.label = now

    @Sketchybar.item(
        position="center",
        properties={"icon.drawing": "off"},
        label="notch_placeholder_0",
    )
    def c0_notch(self):
        pass


if __name__ == "__main__":
    sb = MyAwesomeSketchyBar()

API Reference

Sketchybar Class

Main class for configuring SketchyBar.

Methods

  • post_init(): Contains initial configuration settings and setup. Also item initialization occurs here.
  • do(): Executes sketchybar with provided arguments.
  • run(): Executes any shell command with arguments.
  • autoload(): Finds all decorated methods in the class and runs them in alphabetical order. Alternatively, you can call them manually in post_init() in your preferred order.

Decorators

  • @Sketchybar.item: Define a new bar item with properties

Item Properties

Common properties that can be used in item definitions:

  • position: "left", "right", or "center".
  • update_freq: Update frequency in seconds.
  • subscribe: List of events to subscribe to.
  • properties: Dictionary of additional properties.
  • You can use any sketchybar item properties.

License

This project is licensed under the MIT License

Author

Dmitry Kuznetsov

Related

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sketchybar_py-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sketchybar_py-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file sketchybar_py-0.1.0.tar.gz.

File metadata

  • Download URL: sketchybar_py-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.25

File hashes

Hashes for sketchybar_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b7a613b94a5172265bbcab79a88f8375ebf9ef2ffd8a9687411c134b3facc345
MD5 f5f30c73f43c5a32dcd215d19129976c
BLAKE2b-256 3269ddb1cc99d70b5799a998edd7bbd62bc23e6424057b31aec203e48c3d1be6

See more details on using hashes here.

File details

Details for the file sketchybar_py-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sketchybar_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f120685463792c673c9ecba795b96b98e62c0bcfe801fc87c0a0a5b4c380017d
MD5 604eca33274564603f85002e0ca1038e
BLAKE2b-256 450bf921073977689b3ec7908c50470205fea9647a3697a231f7ae3615f73a7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page