yadm-config/.config/hypr/scripts/MediaCtrl.sh

86 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
# Playerctl
iconPath="/usr/share/icons/Qogir/24/actions"
nextIcon="$iconPath/gtk-media-next-ltr.svg"
previousIcon="$iconPath/gtk-media-previous-ltr.svg"
stopIcon="$iconPath/gtk-media-stop.svg"
playIcon="$iconPath/gtk-media-play-ltr.svg"
pauseIcon="$iconPath/gtk-media-pause.svg"
# Play the next track
play_next() {
playerctl next
show_music_notification next
}
# Play the previous track
play_previous() {
playerctl previous
show_music_notification previous
}
# Toggle play/pause
toggle_play_pause() {
playerctl play-pause
show_music_notification toggle
}
# Stop playback
stop_playback() {
playerctl stop
notify-send -e -u low -i $stopIcon " Playback:" " Stopped"
}
# Display notification with song information
show_music_notification() {
sleep 0.5s
status=$(playerctl status)
icon=""
case "$1" in
"next")
icon=$nextIcon
;;
"previous")
icon=$previousIcon
;;
"toggle")
if [[ "$status" == "Paused" ]]; then
icon=$pauseIcon
else
icon=$playIcon
fi
;;
esac
if [[ "$status" == "Playing" ]]; then
song_title=$(playerctl metadata title)
song_artist=$(playerctl metadata artist)
notify-send -e -u low -i $icon "Now Playing:" "$song_title by $song_artist"
elif [[ "$status" == "Paused" ]]; then
notify-send -e -u low -i $icon " Playback:" " Paused"
fi
}
# Get media control action from command line argument
case "$1" in
"--nxt")
play_next
;;
"--prv")
play_previous
;;
"--pause")
toggle_play_pause
;;
"--stop")
stop_playback
;;
*)
echo "Usage: $0 [--nxt|--prv|--pause|--stop]"
exit 1
;;
esac