-
What am I doing wrong here, I'm trying to get popup to open on mouse hover weather item, but I can only get it to toggle, can someone help on how to handle events properly please? item/weather.sh #!/bin/bash
# Load global styles, colors, and icons
source "$CONFIG_DIR/globalstyles.sh"
# Source weather data script to fetch the latest values
source "$PLUGIN_DIR/weather.sh"
# Weather Item Configuration (shows icon and temperature in the main item)
weather=(
"${menu_defaults[@]}"
icon="$ICON"
label="$TEMP$DEGREE"
icon.font.size=14
popup.align=left
click_script="sketchybar --set weather popup.drawing=toggle"
)
# Weather Popup Items Configuration (for the popup)
weather_current_label=(
"${menu_item_defaults[@]}"
icon="Current Weather"
label=""
"${separator[@]}"
)
weather_current_temp=(
"${menu_item_defaults[@]}"
icon="$ICON"
label="$CONDITION_TEXT, $TEMP$DEGREE"
)
weather_feels_like=(
"${menu_item_defaults[@]}"
icon=""
label="Feels like $FEELSLIKE$DEGREE"
)
weather_humidity=(
icon=""
"${menu_item_defaults[@]}"
label="Humidity: $HUMIDITY%"
)
weather_location=(
"${menu_item_defaults[@]}"
icon=""
label="Location: $LOCATION"
)
weather_spacer=(
"${menu_item_defaults[@]}"
label=""
)
# Weather Popup Configuration (including 5-day forecast)
weather_forecast_label=(
"${menu_item_defaults[@]}"
icon="5-Day Forecast"
label=""
"${separator[@]}"
)
# Add the weather item and set its properties
sketchybar \
--add item weather right \
--set weather "${weather[@]}" \
--subscribe weather mouse.entered mouse.exited mouse.exited.global \
--add item weather.current_label popup.weather \
--set weather.current_label "${weather_current_label[@]}" \
--add item weather.current_temp popup.weather \
--set weather.current_temp "${weather_current_temp[@]}" \
--add item weather.feels_like popup.weather \
--set weather.feels_like "${weather_feels_like[@]}" \
--add item weather.humidity popup.weather \
--set weather.humidity "${weather_humidity[@]}" \
--add item weather.location popup.weather \
--set weather.location "${weather_location[@]}" \
--add item weather.spacer popup.weather \
--set weather.spacer "${weather_spacer[@]}" \
--add item weather.forecast_label popup.weather \
--set weather.forecast_label "${weather_forecast_label[@]}"
# Iterate through the forecast days and add each with icon and label
for i in $(seq 0 4); do
ICON="${FORECAST_ICONS[$i]}" # Set the icon for each forecast day
FORECAST_LABEL="${FORECAST[$i]}" # Get the label for each forecast day
sketchybar --add item weather.forecast_day_$i popup.weather \
--set weather.forecast_day_$i \
icon="$ICON" \
label="$FORECAST_LABEL" \
icon.padding_right=5 \
"${menu_item_defaults[@]}"
done plugin/weather.sh #!/bin/bash
# Load global styles, colors, and icons
source "$CONFIG_DIR/globalstyles.sh"
# Map OpenWeatherMap icon codes to Nerd Font icons
map_icon() {
case $1 in
01d) echo "" ;; # Clear sky day
01n) echo "" ;; # Clear sky night
02d) echo "" ;; # Few clouds day
02n) echo "" ;; # Few clouds night
03d | 03n) echo "" ;; # Scattered clouds
04d | 04n) echo "" ;; # Broken clouds
09d | 09n) echo "" ;; # Shower rain
10d) echo "" ;; # Rain day
10n) echo "" ;; # Rain night
11d | 11n) echo "" ;; # Thunderstorm
13d | 13n) echo "" ;; # Snow
50d | 50n) echo "" ;; # Mist
*) echo "" ;; # Default icon for unknown cases
esac
}
# Fetch current weather data and 5-day forecast from OpenWeatherMap
CITY="Attleboro"
COUNTRY="US"
API_KEY="***"
UNITS="imperial"
DEGREE="°F"
# Fetch current weather data
DATA=$(curl -s "http://api.openweathermap.org/data/2.5/weather?q=$CITY,$COUNTRY&appid=$API_KEY&units=$UNITS")
# Fetch 5-day forecast data
FORECAST_DATA=$(curl -s "http://api.openweathermap.org/data/2.5/forecast?q=$CITY,$COUNTRY&appid=$API_KEY&units=$UNITS")
# Extract current weather data
TEMP=$(echo "$DATA" | jq -r '.main.temp | floor')
FEELSLIKE=$(echo "$DATA" | jq -r '.main.feels_like | floor')
CONDITION_TEXT=$(echo "$DATA" | jq -r '.weather[0].main')
HUMIDITY=$(echo "$DATA" | jq -r '.main.humidity')
LOCATION=$(echo "$DATA" | jq -r '.name')
ICON_CODE=$(echo "$DATA" | jq -r '.weather[0].icon')
# Get the current icon for the weather item
ICON=$(map_icon "$ICON_CODE")
# Declare arrays for the forecast
declare -a FORECAST=()
declare -a FORECAST_ICONS=()
# Extract 5-day forecast data (every 8th entry is roughly one day apart)
for i in $(seq 0 4); do
# Get the date for each forecast entry
DATE=$(echo "$FORECAST_DATA" | jq -r ".list[$((i * 8))].dt_txt | .[0:10]")
# Convert date (YYYY-MM-DD) to day of the week (MON, TUE, etc.)
DAY=$(date -jf "%Y-%m-%d" "$DATE" +"%a")
# Get forecast details
DAY_CONDITION=$(echo "$FORECAST_DATA" | jq -r ".list[$((i * 8))].weather[0].main")
DAY_TEMP=$(echo "$FORECAST_DATA" | jq -r ".list[$((i * 8))].main.temp | floor") # Extract temperature correctly
ICON_CODE=$(echo "$FORECAST_DATA" | jq -r ".list[$((i * 8))].weather[0].icon")
ICON=$(map_icon "$ICON_CODE")
# Store the icon and forecast label for each day
FORECAST_ICONS+=("$ICON")
FORECAST+=("$DAY: ${DAY_TEMP}°F $DAY_CONDITION")
done
# Debugging final arrays
echo "FORECAST: ${FORECAST[*]}"
echo "FORECAST_ICONS: ${FORECAST_ICONS[*]}"
# Export both FORECAST and FORECAST_ICONS for use in the items script
export TEMP FEELSLIKE CONDITION_TEXT HUMIDITY LOCATION ICON DEGREE FORECAST FORECAST_ICONS
# Handle popup events
popup() {
case "$1" in
"on")
sketchybar --set weather popup.drawing=on
;;
"off")
sketchybar --set weather popup.drawing=off
;;
esac
}
case "$SENDER" in
"mouse.entered")
popup on
;;
"mouse.exited" | "mouse.exited.global")
popup off
;;
esac |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I have a similar setup to yours, with the following differences. Try them, maybe it will work for you?
Remove line Subscribe to
If you want to take a peek: https://github.com/Pe8er/dotfiles/blob/master/config.symlink/sketchybar/items/weather.sh |
Beta Was this translation helpful? Give feedback.
I have a similar setup to yours, with the following differences. Try them, maybe it will work for you?
Remove line
click_script="sketchybar --set weather popup.drawing=toggle"
Subscribe to
mouse.clicked
:--subscribe weather mouse.entered mouse.exited mouse.exited.global mouse.clicked \
If you want to take a peek:
https://github.com/Pe8er/dotfiles/blob/master/config.symlink/sketchybar/items/weather.sh
https://github.com/Pe8er/dotfile…