它工作正常,但是通知发送被“向后”放置在其他通知之前,这里是:一张图片:
感觉我的通知在不同的“组”或其他地方......
该通知应在 mullvad 通知之后发出。
服务脚本:
[Unit]
Description=Turns off microphone at startup
#After=multi-user.target
After=syslog.target
[Service]
ExecStart=/opt/bin/microphone-status
User=tom
RemainAfterExit=yes
Environment="DISPLAY=:0.0" "XAUTHORITY=/home/tom/.Xauthority"
[Install]
WantedBy=multi-user.target
剧本:
#!/bin/bash
sleep 10
#/usr/bin/update-notifier
/usr/bin/notify-send -u normal 'Why does it appear on top?'
#function check_state () {
# toggle_toggle=$(/usr/bin/amixer get Capture | grep -c "\[off\]")
# echo toggle+percent
# toggle_percent=$(/usr/bin/amixer get Capture | grep -c "\[0%\]")
# echo toggle_percent
# let toggle_result=$((toggle_toggle+toggle_percent))
# echo $((toggle_result))
#}
#check_state
#/usr/bin/notify-send -u normal $toggle_result # IF 4 = TURNED OFF, IF !=4 TURNED ON
#if [ $(/usr/bin/pgrep pavucontrol) > 0 ] ; then # Check if pavucontrol has processID = active
#echo "found pavucontrol"
# if [ $((toggle_result)) != 4 ] ; then # Turn off microphone once
# toggle off
# /usr/bin/killall -9 xfce4-notifyd
# /usr/bin/notify-send 'Microphone was left turned on' 'It was automatically disabled.'
# /usr/bin/amixer set Capture toggle
# /usr/bin/amixer set Capture 0
# /usr/bin/amixer set Capture 0%
# fi
#fi
exit 0
另一张图片 - 通知开始于一个非常奇怪的地方 - 在我的任务栏的一半
答案1
cat /lib/systemd/system/alsa-volume-default.service
[Unit]
Description=Alsa volume default servivce.
After=alsa-restore.service
PartOf=alsa-restore.service
[Service]
ExecStart=/opt/bin/alsa-controls.sh init
[Install]
WantedBy=alsa-restore.service
猫/home/bac0n/.config/autostart/alsa-controls.desktop
[Desktop Entry]
Comment=Alsa volume notify
Exec=/bin/bash -c "/opt/bin/alsa-controls.sh check; sudo -n /opt/bin/alsa-controls.sh reset"
GenericName=Alsa Volume Notify
Name=AlsaControls
StartupNotify=false
Terminal=false
Type=Application
猫/etc/sudoers.d/alsa-controls
Cmnd_Alias CMDS = /opt/bin/alsa-controls.sh reset
User_Alias CMDUSERS = bac0n
CMDUSERS ALL=(ALL) NOPASSWD: CMDS
Defaults!CMDS env_keep += DBUS_SESSION_BUS_ADDRESS
猫/opt/bin/alsa-controls.sh
#!/bin/bash
file=/var/lib/alsa-controls/state
# alsa-volume-default.service
init(){
local left right state
read -d '' -r left right < <( \
amixer sget DAC,0 | \
sed -nr 's/Front .* \[([0-9]+)%\]$/\1/p')
mkdir -p ${file%/*} || exit 1
# 0 = unchanged, 1 = changed
[[ $left -eq $right \
&& $left -eq 5 ]]; state=$?
amixer -q sset DAC,0 5% && echo $state > $file
}
# Autostart as unprivileged.
check(){
read -r -N 1 < $file || exit
[[ $REPLY = +([1-9]) ]] && \
notify-send -t 0 -u normal "alsa notify" "Alsa volume has been altered."
}
# Autostart as root (sudo).
reset(){
[[ $EUID -eq 0 ]] \
&& echo 0 > $file
}
[[ $1 = @(init|check|reset) ]] && $1
exit 0