Closed jncsotk30 closed 1 year ago
One other note to mention, if I use the $NAME
variable in the music.sh
script, it returns the following error when running script.
However, if you switch to using the manual name of the item, it will work fine. Seems like $NAME
isn't passed into the script. How is that info passed?
I think the problem is that the routine update executed through sketchybar does not find the npcli executable (since scripts run through sketchybar do not have access to variables set in your zshrc). It shows correctly if you execute it in a shell where npcli is added to PATH.
So the solution will probably be to replace npcli with the absolute path to the binary.
The $NAME parameter is set by sketchybar and thus only available when sketchybar ececutes the scripts internally.
Spot on @FelixKratz. That was exactly my problem. I updated the music.sh
script with the absolute path and all is working well now. Next I just gotta setup song change event and wire that up.
#!/bin/sh
# DESCRIPTION: Script will pull now playing information from the Mac system media library.
# DEPENDS: nowplaying-cli(~/.bin)
# Name of executable in $HOME/.bin (symlinked)
NPCLI="$HOME/.bin/npcli"
# Currently playing music info
TRACK="$($NPCLI get title)"
ARTIST="$($NPCLI get artist)"
sketchybar --set music label="$TRACK"
Thanks very much!
Thank you for clarifying about the $NAME
var.
This is my current script
# Name of executable in $HOME/.bin (symlinked)
NPCLI="$HOME/projects/nowplaying-cli/nowplaying-cli"
# Currently playing music info
TRACK="$($NPCLI get title)"
ARTIST="$($NPCLI get artist)"
# Get the duration and elapsed time from the nowplaying-cli
DURATION="$($NPCLI get Duration)"
ELAPSED_TIME="$($NPCLI get ElapsedTime)"
PLAYBACK_RATE="$($NPCLI get PlaybackRate)"
# Convert the elapsed time to minutes and seconds
ELAPSED_MINUTES=$(awk "BEGIN {printf \"%d\", $ELAPSED_TIME/60}")
ELAPSED_SECONDS=$(awk "BEGIN {printf \"%d\", $ELAPSED_TIME%60}")
# Format the seconds to always be two digits
printf -v ELAPSED_SECONDS "%02d" $ELAPSED_SECONDS
# Calculate the percentage of the song elapsed
PERCENTAGE=$(bc -l <<< "$ELAPSED_TIME*100/$DURATION")
PERCENTAGE=$(printf "%.0f" $PERCENTAGE) # Round to the nearest whole number
# Display the result in the requested format
TIME="${ELAPSED_MINUTES}:${ELAPSED_SECONDS} ${PERCENTAGE}%"
# Set PLAYBACK_STATE based on the playback rate
if [ "$PLAYBACK_RATE" == "0" ]; then
PLAYBACK_STATE="[PAUSED]"
else
PLAYBACK_STATE="$TIME"
fi
sketchybar --set music label="$TRACK · $ARTIST $PLAYBACK_STATE"
First off, well done to the developers on SketchyBar! I'm loving it so far and am excited to see what else can be done.
That said, I'm experiencing a quirk with my music / now playing "widget". It's tied to a very basic script which depends on a CLI utility called nowplaying-cli. This is used to retrieve media information like track title, track artist etc. I pass the resulting data from this script into the label field. It will display properly for a brief moment, but then disappears after 1 or 2 seconds.
The
update_freq
is set to3
, but I don't believe that's where the problem resides. Not quite sure what's going on here.Could someone please help me identify the problem if possible?
sketchybarrc
music.sh
https://github.com/FelixKratz/SketchyBar/assets/125376259/c3e7aa0b-5ac1-481c-82d3-8f011a4de425