Git Product home page Git Product logo

Comments (7)

jgroboredo avatar jgroboredo commented on August 22, 2024 2

Would an on-screen-display built separately for indicating volume and brightness changes be something you would desire as an alternative for having to handle such things via notifications?

I think it would suffice, yes!

Also could you share your script please?

Here's the script:

#!/bin/bash
# Scripts for volume controls for audio and mic

iDIR="$HOME/.config/swaync/icons"

# Get Volume
get_volume() {
    volume=$(pamixer --get-volume)
    if [[ "$volume" -eq "0" ]]; then
        echo "Muted"
    else
        echo "$volume%"
    fi
}

# Get icons
get_icon() {
    current=$(get_volume)
    if [[ "$current" == "Muted" ]]; then
        echo "$iDIR/volume-mute.png"
    elif [[ "${current%\%}" -le 30 ]]; then
        echo "$iDIR/volume-low.png"
    elif [[ "${current%\%}" -le 60 ]]; then
        echo "$iDIR/volume-mid.png"
    else
        echo "$iDIR/volume-high.png"
    fi
}

# Notify
notify_user() {
    if [[ "$(get_volume)" == "Muted" ]]; then
        notify-send -e -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: Muted"
    else
        notify-send -r 1234 -e -h int:value:"$(get_volume | sed 's/%//')" -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: $(get_volume)"
    fi
}

# Increase Volume
inc_volume() {
    if [ "$(pamixer --get-mute)" == "true" ]; then
        pamixer -u && notify_user
    fi
    pamixer -i 5 && notify_user
}

# Decrease Volume
dec_volume() {
    if [ "$(pamixer --get-mute)" == "true" ]; then
        pamixer -u && notify_user
    fi
    pamixer -d 5 && notify_user
}

# Toggle Mute
toggle_mute() {
	if [ "$(pamixer --get-mute)" == "false" ]; then
		pamixer -m && notify-send -e -u low -i "$iDIR/volume-mute.png" "Volume Switched OFF"
	elif [ "$(pamixer --get-mute)" == "true" ]; then
		pamixer -u && notify-send -e -u low -i "$(get_icon)" "Volume Switched ON"
	fi
}

# Toggle Mic
toggle_mic() {
	if [ "$(pamixer --default-source --get-mute)" == "false" ]; then
		pamixer --default-source -m && notify-send -e -u low -i "$iDIR/microphone-mute.png" "Microphone Switched OFF"
	elif [ "$(pamixer --default-source --get-mute)" == "true" ]; then
		pamixer -u --default-source u && notify-send -e -u low -i "$iDIR/microphone.png" "Microphone Switched ON"
	fi
}
# Get Mic Icon
get_mic_icon() {
    current=$(pamixer --default-source --get-volume)
    if [[ "$current" -eq "0" ]]; then
        echo "$iDIR/microphone-mute.png"
    else
        echo "$iDIR/microphone.png"
    fi
}

# Get Microphone Volume
get_mic_volume() {
    volume=$(pamixer --default-source --get-volume)
    if [[ "$volume" -eq "0" ]]; then
        echo "Muted"
    else
        echo "$volume%"
    fi
}

# Notify for Microphone
notify_mic_user() {
    volume=$(get_mic_volume)
    icon=$(get_mic_icon)
    notify-send -e -h int:value:"$volume" -h "string:x-canonical-private-synchronous:volume_notif" -u low -i "$icon" "Mic-Level: $volume"
}

# Increase MIC Volume
inc_mic_volume() {
    if [ "$(pamixer --default-source --get-mute)" == "true" ]; then
        pamixer --default-source -u && notify_mic_user
    fi
    pamixer --default-source -i 5 && notify_mic_user
}

# Decrease MIC Volume
dec_mic_volume() {
    if [ "$(pamixer --default-source --get-mute)" == "true" ]; then
        pamixer --default-source -u && notify_mic_user
    fi
    pamixer --default-source -d 5 && notify_mic_user
}

# Execute accordingly
if [[ "$1" == "--get" ]]; then
	get_volume
elif [[ "$1" == "--inc" ]]; then
	inc_volume
elif [[ "$1" == "--dec" ]]; then
	dec_volume
elif [[ "$1" == "--toggle" ]]; then
	toggle_mute
elif [[ "$1" == "--toggle-mic" ]]; then
	toggle_mic
elif [[ "$1" == "--get-icon" ]]; then
	get_icon
elif [[ "$1" == "--get-mic-icon" ]]; then
	get_mic_icon
elif [[ "$1" == "--mic-inc" ]]; then
	inc_mic_volume
elif [[ "$1" == "--mic-dec" ]]; then
	dec_mic_volume
elif [[ "$1" == "--player" ]]; then
    # Shitft arguments - expecting player name after --player flag
    shift
    target_player="$1"
    nsink=$(playerctl --list-all | grep -w "${target_player}" | cut -d ":" -f 2)
    [ -z "${nsink}" ] && echo "ERROR: Player ${target_player} not active..." && exit 0

    # Shitft arguments - expecting action after
    shift
    action=$1
    [ "${action}" == "i" ] && pvl="+" || pvl="-"

    playerctl --player="${nsink}" volume 0.0"5""${pvl}"
    vol=$(playerctl --player="${nsink}" volume | awk '{ printf "%.0f\n", $0 * 100 }')

    notify-send -e -h int:value:"$(echo "$vol" | sed 's/%//')" -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: ${vol}"
else
	get_volume
fi

Edit: This script is adapted from some other scripts I've found during the time - any resemblance is not coincidence, but I have lost the sources unfortunately.

Let me know if you need the icons for the notifications.

from ags-top-panel.

Jas-SinghFSU avatar Jas-SinghFSU commented on August 22, 2024 1

Added on-screen-displays to indicate volume and brightness changes.

The settings for this can be configured in Configuration > General and coloring in Theming > OSD.

from ags-top-panel.

Jas-SinghFSU avatar Jas-SinghFSU commented on August 22, 2024

You can provide an ID in the notify-send command so that all messages originating from the same id won't spam you. To do this you can provide an -r 1234 flag where 1234 is your id.
Example:

notify-send -r 1234 -e -h int:value:"$(get_volume)" -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: $(get_volume)"

from ags-top-panel.

jgroboredo avatar jgroboredo commented on August 22, 2024

Thanks for your reply.

That does indeed work, but I'm still missing the display of the value hint. This is an example of the exact same notification using swaync:

image

And using AGS notification daemon:

image

from ags-top-panel.

Jas-SinghFSU avatar Jas-SinghFSU commented on August 22, 2024

Would an on-screen-display built separately for indicating volume and brightness changes be something you would desire as an alternative for having to handle such things via notifications?

from ags-top-panel.

Jas-SinghFSU avatar Jas-SinghFSU commented on August 22, 2024

Also could you share your script please?

from ags-top-panel.

jgroboredo avatar jgroboredo commented on August 22, 2024

Great, looking forward to test it out!

from ags-top-panel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.