在 Linux Mint 17 中,我将时间Suspend when inactive for
设置Power Management
为 10 分钟。
问题是,即使我正在使用以下命令听音乐,系统也会挂起Spotify。
有什么办法可以防止这种情况发生吗?
答案1
我发现本文这建议了几种阻止屏幕保护程序激活的方法。我还没有对此进行测试,但由于他们可能会发出事件来停止激活(至少第二个是这样),因此这也应该算作不活动监视器的活动。不过你必须测试一下,我不确定它是否有效。
安装
caffeine
。这可以通过将 a 添加ppa
到您的系统,然后像任何其他软件包一样安装它来完成。只要您使用普通的 Mint,这也应该适合您。sudo add-apt-repository ppa:caffeine-developers/ppa sudo apt-get update sudo apt-get install caffeine
然后,启动
caffeine
及其图标应该出现在您的系统托盘中。您可以选择哪些程序应取消暂停。笔记:截至2.7 咖啡因的释放,该程序不再具有 GUI,仅作为守护程序运行。运行时,只要活动窗口是全屏,它就会阻止屏幕保护程序激活。
这开灯脚本。默认情况下它不会检查 Spotify,但很容易修改它来执行此操作。只需在脚本开头添加
spotify
到数组中即可:delay_progs
delay_progs=("spotify")
然后,将该脚本添加到启动程序中,以便它在后台运行。如果 Spotify 正在运行,它应该会阻止您暂停。请注意,这不会检查是否有音乐正在播放,而只是检查程序是否正在运行。
如果这些对暂停不起作用,请告诉我,我会尝试使用xdotool
或类似的程序将一些东西组合在一起。
答案2
我刚刚发布了类似问题的答案: Linux Mint:如何避免在播放音乐时暂停
我编写了一个脚本,在 pactl 检测到正在运行的音频源时将挂起超时设置为“从不”,然后在未检测到音频源时恢复设置。
这是最新答案和脚本的副本:
我对上面的脚本做了更多的工作,它现在应该可以在运行 Gnome 的 Cinnamon、Mate 和 Ubuntu 中运行。我已经在 Linux Mint 19 Cinnamon 和 Mate 的 Live USB 版本以及 Ubuntu 18.04 - Gnome 上进行了尝试。
#!/bin/sh
# Audiocaffeine
# Works in Linux Mint 19 - Cinnamon, Linux Mint 19 - Mate, Ubuntu 18.04 - Gnome
# Script to temporarily set suspend timout for AC and battery to "Never"
# while audio is playing. It then reverts the settings when audio is no longer detected.
# Determine if a valid desktop environment is running and exit if it doesn't.
echo "Reported desktop environment: ""$XDG_CURRENT_DESKTOP"
if [ "$XDG_CURRENT_DESKTOP" = "X-Cinnamon" ]; then
actimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout"
batttimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout"
disablevalue=0
elif [ "$XDG_CURRENT_DESKTOP" = "MATE" ]; then
actimeoutid="org.mate.power-manager sleep-computer-ac"
batttimeoutid="org.mate.power-manager sleep-computer-battery"
disablevalue=0
elif [ "$XDG_CURRENT_DESKTOP" = "ubuntu:GNOME" ]; then
actimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type"
batttimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type"
disablevalue="nothing"
else
echo "No valid desktop environment is running"
exit 1
fi
# Create .config directory to store settings if it doesn't exist.
if [ ! -d ~/.config ]; then
echo ".config directory not found!"
echo "Creating ~/.config"
mkdir ~/.config
fi
# Create audiocaffeine directory to store settings if it doesn't exist.
if [ ! -d ~/.config/audiocaffeine ]; then
echo "Configuration directory not found!"
echo "Creating ~/.config/audiocaffeine"
mkdir ~/.config/audiocaffeine
fi
# Restore previous value for AC suspend timeout if script
# was interrupted.
if [ -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Restoring previous AC suspend timeout."
read acsuspendtime < ~/.config/audiocaffeine/acsuspend
gsettings set $actimeoutid $acsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
rm ~/.config/audiocaffeine/acsuspend
fi
# Restore previous value for battery suspend timeout if script
# was interrupted.
if [ -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Restoring previous battery suspend timeout."
read battsuspendtime < ~/.config/audiocaffeine/battsuspend
gsettings set $batttimeoutid $battsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
rm ~/.config/audiocaffeine/battsuspend
fi
# Start main loop to check if audio is playing
while true; do
# Use pactl to detect if there are any running audio sources.
if pactl list | grep -q "State: RUNNING"; then
echo "Audio detected."
# If AC timeout was not previously saved, then save it.
if [ ! -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Saving current AC suspend timeout."
gsettings get $actimeoutid > ~/.config/audiocaffeine/acsuspend
fi
# If battery timeout was not previously saved, then save it.
if [ ! -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Saving current battery suspend timeout."
gsettings get $batttimeoutid > ~/.config/audiocaffeine/battsuspend
fi
# Set the suspend timouts to Never using gsettings.
echo "Changing suspend timeouts."
gsettings set $actimeoutid $disablevalue
gsettings set $batttimeoutid $disablevalue
else
echo "No audio detected."
# Restore previous value for AC suspend timeout and delete the
# temporary file storing it.
if [ -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Restoring previous AC suspend timeout."
read acsuspendtime < ~/.config/audiocaffeine/acsuspend
gsettings set $actimeoutid $acsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
rm ~/.config/audiocaffeine/acsuspend
fi
# Restore previous value for battery suspend timeout and delete the
# temporary file storing it.
if [ -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Restoring previous battery suspend timeout."
read battsuspendtime < ~/.config/audiocaffeine/battsuspend
gsettings set $batttimeoutid $battsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
rm ~/.config/audiocaffeine/battsuspend
fi
fi
# Pause the script for 60 seconds before doing the loop again.
sleep 60s
done
答案3
我向 Jason Gambrel 的脚本添加了 GNOME Flashback 支持。这个版本还包括他的 ALSA 支持系列,而不仅仅是 PulseAudio。要启用 ALSA 支持,您必须手动取消注释并注释代码中的两行(在代码注释中标识)。我本可以让它自动检测所使用的内容,但我认为这对于大多数系统上可能永远不会改变的东西来说是一种浪费,而且现在大多数人都使用 PA 或带有 PA 模拟的 PipeWire。我可以确认除了 Jason 测试过的之外,它还适用于 Ubuntu 23.04。
由于发帖限制,我无法将其添加到 Jason 最初发布的问题中或作为他的脚本下的评论,而且我是 Stack Exchange 社区这个角落的新手。如果某个模组想要移动它并使其成为他的评论,我对此非常满意。
#!/bin/sh
# Audiocaffeine - Pulseaudio
# Original by Jason Gambrel
# https://unix.stackexchange.com/questions/340651/linux-mint-how-to-avoid-suspending-while-music-is-playing
# Works in Linux Mint 19 - Cinnamon, Linux Mint 19 - Mate, Ubuntu 18.04-23.04 - Gnome
# Gnome Flashback support added by Joseph Lathem (aka Sienile)
# Script to temporarily set suspend timout for AC and battery to "Never"
# while audio is playing. It then reverts the settings when audio is no longer detected.
# Determine if a valid desktop environment is running and exit if it doesn't.
echo "Reported desktop environment: ""$XDG_CURRENT_DESKTOP"
if [ "$XDG_CURRENT_DESKTOP" = "X-Cinnamon" ]; then
actimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout"
batttimeoutid="org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout"
disablevalue=0
elif [ "$XDG_CURRENT_DESKTOP" = "MATE" ]; then
actimeoutid="org.mate.power-manager sleep-computer-ac"
batttimeoutid="org.mate.power-manager sleep-computer-battery"
disablevalue=0
elif [ "$XDG_CURRENT_DESKTOP" = "ubuntu:GNOME" ]; then
actimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type"
batttimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type"
disablevalue="nothing"
elif [ "$XDG_CURRENT_DESKTOP" = "GNOME-Flashback:GNOME" ]; then
actimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type"
batttimeoutid="org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type"
disablevalue="nothing"
else
echo "No valid desktop environment is running"
exit 1
fi
# Create .config directory to store settings if it doesn't exist.
if [ ! -d ~/.config ]; then
echo ".config directory not found!"
echo "Creating ~/.config"
mkdir ~/.config
fi
# Create audiocaffeine directory to store settings if it doesn't exist.
if [ ! -d ~/.config/audiocaffeine ]; then
echo "Configuration directory not found!"
echo "Creating ~/.config/audiocaffeine"
mkdir ~/.config/audiocaffeine
fi
# Restore previous value for AC suspend timeout if script
# was interrupted.
if [ -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Restoring previous AC suspend timeout."
read acsuspendtime < ~/.config/audiocaffeine/acsuspend
gsettings set $actimeoutid $acsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
rm ~/.config/audiocaffeine/acsuspend
fi
# Restore previous value for battery suspend timeout if script
# was interrupted.
if [ -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Restoring previous battery suspend timeout."
read battsuspendtime < ~/.config/audiocaffeine/battsuspend
gsettings set $batttimeoutid $battsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
rm ~/.config/audiocaffeine/battsuspend
fi
# Start main loop to check if audio is playing
while true; do
# If using ALSA instead of PulseAudio or PipeWire with PA emulation, uncomment the next if statement and comment the one for pactl
# Use ALSA to detect if there are any running audio sources.
#if grep -q RUNNING /proc/asound/card*/*p/*/status 2>&1; then
# Use pactl to detect if there are any running audio sources.
if pactl list | grep -q "State: RUNNING"; then
echo "Audio detected."
# If AC timeout was not previously saved, then save it.
if [ ! -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Saving current AC suspend timeout."
gsettings get $actimeoutid > ~/.config/audiocaffeine/acsuspend
fi
# If battery timeout was not previously saved, then save it.
if [ ! -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Saving current battery suspend timeout."
gsettings get $batttimeoutid > ~/.config/audiocaffeine/battsuspend
fi
# Set the suspend timouts to Never using gsettings.
echo "Changing suspend timeouts."
gsettings set $actimeoutid $disablevalue
gsettings set $batttimeoutid $disablevalue
else
echo "No audio detected."
# Restore previous value for AC suspend timeout and delete the
# temporary file storing it.
if [ -f ~/.config/audiocaffeine/acsuspend ]; then
echo "Restoring previous AC suspend timeout."
read acsuspendtime < ~/.config/audiocaffeine/acsuspend
gsettings set $actimeoutid $acsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/acsuspend"
rm ~/.config/audiocaffeine/acsuspend
fi
# Restore previous value for battery suspend timeout and delete the
# temporary file storing it.
if [ -f ~/.config/audiocaffeine/battsuspend ]; then
echo "Restoring previous battery suspend timeout."
read battsuspendtime < ~/.config/audiocaffeine/battsuspend
gsettings set $batttimeoutid $battsuspendtime
echo "Removing temporary file ~/.config/audiocaffeine/battsuspend"
rm ~/.config/audiocaffeine/battsuspend
fi
fi
# Pause the script for 60 seconds before doing the loop again.
sleep 60s
done