blob: dd55b0ae46edc61f9be632bad2e35c7f591466ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/usr/bin/env bash
# Source colors for consistent theming
source "$CONFIG_DIR/colors.sh"
# Get CPU usage percentage
CPU_USAGE=$(top -l 1 -n 0 | grep "CPU usage" | awk '{print $3}' | sed 's/%//')
# Handle empty CPU usage
if [[ -z "$CPU_USAGE" ]]; then
CPU_USAGE=0
fi
# Remove decimal point for comparison
CPU_INT=${CPU_USAGE%.*}
# Set icon and color based on CPU usage
if [[ $CPU_INT -le 25 ]]; then
ICON="" # Low CPU
COLOR=$ACCENT_SECONDARY # Green
elif [[ $CPU_INT -le 50 ]]; then
ICON="" # Medium CPU
COLOR=$ACCENT_PRIMARY # Blue
elif [[ $CPU_INT -le 75 ]]; then
ICON="" # High CPU
COLOR=$ACCENT_TERTIARY # Orange
else
ICON="" # Very High CPU
COLOR=$RED # Red
fi
# Update the CPU item
sketchybar --set "$NAME" icon="$ICON" \
icon.color="$COLOR" \
label="$CPU_USAGE%" \
label.color=$WHITE \
label.font="SF Pro:Medium:12.0"
|