irongit
hygoland/scripts/MediaCtrl.sh
61 lines1.3 KBBourne Again Shell (bash)
1#!/bin/bash
2# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
3# Playerctl
4
5music_icon="$HOME/.config/swaync/icons/music.png"
6
7# Play the next track
8play_next() {
9 playerctl next
10 show_music_notification
11}
12
13# Play the previous track
14play_previous() {
15 playerctl previous
16 show_music_notification
17}
18
19# Toggle play/pause
20toggle_play_pause() {
21 playerctl play-pause
22 show_music_notification
23}
24
25# Stop playback
26stop_playback() {
27 playerctl stop
28 notify-send -e -u low -i $music_icon " Playback:" " Stopped"
29}
30
31# Display notification with song information
32show_music_notification() {
33 status=$(playerctl status)
34 if [[ "$status" == "Playing" ]]; then
35 song_title=$(playerctl metadata title)
36 song_artist=$(playerctl metadata artist)
37 notify-send -e -u low -i $music_icon "Now Playing:" "$song_title by $song_artist"
38 elif [[ "$status" == "Paused" ]]; then
39 notify-send -e -u low -i $music_icon " Playback:" " Paused"
40 fi
41}
42
43# Get media control action from command line argument
44case "$1" in
45 "--nxt")
46 play_next
47 ;;
48 "--prv")
49 play_previous
50 ;;
51 "--pause")
52 toggle_play_pause
53 ;;
54 "--stop")
55 stop_playback
56 ;;
57 *)
58 echo "Usage: $0 [--nxt|--prv|--pause|--stop]"
59 exit 1
60 ;;
61esac