単純な問題があります。コンピューターのデスクトップアプリケーションで音楽が再生中のときにコンピューターが中断しないようにしたい-もっとうまくやりたい音楽アプリケーションがopenであるときはいつでも、コンピューターを起動状態に保つスクリプトよりも。 Linux Mint18を実行しています。
アプリケーションごとに機能する可能性があると思いますが、通常のシナモンサウンドアプレット(または同様のもの)を利用してこれを行う方法があるかどうかも疑問に思います。そのアプレットは、ユーザーが開いている音楽アプリケーション(Spotify、Clementine、Bansheeなど)の再生を検出して制御できます。スクリプトがサウンドアプレットまたは特定のアプリケーションから音楽が再生されているかどうかを判断する方法はありますか?
私はこの質問を知っています: Spotifyで音楽を再生しているときにミントが中断するのを防ぎます しかし、受け入れられた答えは問題を解決せず、カフェインはそれ以来完全に変わりました。
私の望ましい行動はいくつかの理由で有益です:
私はこれをハックするつもりですが、この種のスクリプトを書いたことがなく、どこから始めればよいのかわかりません。これは非常に基本的でありながら便利であると感じているので、おそらくMintの機能要求であるはずです。
私はこれと同じことで苦労してきました。 pactlを使用してpulseaudioのステータスをチェックすることについて話している他のいくつかの投稿を見つけました。ここに1つのリンクがあります:
https://superuser.com/questions/393448/detecting-audio-playing-in-a-bash-script
私は、Cinnamonの電源設定の一時停止タイムアウトを、音楽の再生中に一時的に停止せず、音楽が停止すると元に戻す非常に単純なスクリプトを作成しようとしました。これはスクリプトでの私の最初の実際の試みなので、改善できる場合はお気軽に。ただし、シナモンでのみ機能する可能性があります。
#!/bin/sh
# Script to temporarily set Cinnamon's suspend timout for AC and battery to "Never"
# while audio is playing. It then reverts the settings when audio is no longer detected.
# Create 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 org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout $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 org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout $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 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 org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout > ~/.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 org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout > ~/.config/audiocaffeine/battsuspend
fi
# Set the suspend timouts to Never using gsettings.
echo "Changing suspend timeouts."
gsettings set org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
gsettings set org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout 0
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 org.cinnamon.settings-daemon.plugins.power sleep-inactive-ac-timeout $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 org.cinnamon.settings-daemon.plugins.power sleep-inactive-battery-timeout $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
上記のスクリプトでもう少し作業を行いましたが、Gnomeを実行しているCinnamon、Mate、Ubuntuで動作するはずです。 Linux Mint 19CinnamonとMateのライブUSBバージョンとUbuntu18.04-Gnomeで試してみました。これが他の何人かの人々に役立つことを願っています。
ジェイ
#!/bin/sh
# Audiocaffeine - Pulseaudio
# 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
または、Pulseaudioの代わりにALSAを使用するバージョンは次のとおりです。
#!/bin/sh
# Audiocaffeine - ALSA
# 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 ALSA to detect if there are any running audio sources.
if grep -q RUNNING /proc/asound/card*/*p/*/status 2>&1; 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
ソフトウェアマネージャーからカフェインアプリをダウンロードしてインストールします。次に、デスクトップパネルにカフェインインジケーターをインストールします。次に、自由にカフェインをアクティブ化または非アクティブ化することを選択できます。 Linux Mint MATE 19.3でうまく機能します。