簡単な質問があります。音楽を再生するときにコンピュータが一時停止しないようにしたいと思います。遊ぶ私のコンピュータのデスクトップアプリケーションで - スクリプトよりも優れた作業を行い、音楽アプリケーションの実行中に自分のコンピュータをアクティブにしたいと思います。開いている。私はLinux Mint 18を使用しています。
アプリごとに動作できると思いますが、一般的なCinnamonサウンドアプレット(または同様のもの)を活用してこれを行う方法があるかどうかを知りたいです。アプレットは、Spotify、Clementine、Bansheeなど、ユーザーが開いたすべての音楽アプリで再生を検出して制御できます。音楽がサウンドアプレットまたは特定のアプリケーションで再生されるかどうかをスクリプトで確認する方法はありますか?
私はこの質問を知っています:Spotifyで音楽を再生しながらMintが一時停止しないようにするしかし、受け入れられた答えは問題を解決できませんでした。それ以来、カフェインは完全に変わりました。
私が望む行動は、次の理由で有益です。
- ユーザーがバックグラウンドで音楽アプリを開いたままにしても再生が停止しても、コンピュータは無期限にアクティブになりません。
- ユーザーがコンピュータから離れている間に音楽を再生して音楽を再生し続けたい場合は、音楽再生を続行するために音楽プレーヤーが全画面表示されることを心配する必要はありません。
- ユーザーはさまざまな方法でこの動作を利用できます。たとえば、寝る前に快適な音楽を20分間選択できます。 20分のプレイリストが終了すると、コンピュータは一晩中一時停止します。したがって、プレイリストの長さに合わせて睡眠時間が自動的に調整されます。
私はこの問題を解決したいのですが、このような性格のスクリプトを書いたことがないので、どこから始めるべきかわかりません。これは基本的ですが便利です。おそらくMintの機能要求であるべきです。
答え1
私も同じことで苦労しています。 pulseaudioの状態を確認するためにpactlを使用することについて議論する他の記事を見つけました。以下はリンクです:
https://superuser.com/questions/393448/Detecting-audio-playing-in-a-bash-script
私は音楽の再生中にCinnamonの電源設定で一時停止タイムアウトをNeverに変更し、音楽が停止したときに再起動する非常に簡単なスクリプトを作成しようとしています。これはスクリプトを書くための私の最初の実際の試みなので、改善できる場合は自由に感じてください。しかし、シナモンにのみ効果があるかもしれません。
#!/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
答え2
上記のスクリプトについてもう少し作業を行いましたが、Gnomeを実行しているCinnamon、Mate、Ubuntuで動作します。私はLinux Mint 19 CinnamonとLive USBバージョンのMateだけでなく、Ubuntu 18.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
答え3
ソフトウェアマネージャからCaffeineアプリをダウンロードしてインストールします。次に、デスクトップパネルにCaffeine Indicatorをインストールします。その後、レジャー時にカフェインを有効または無効にすることを選択できます。 Linux Mint MATE 19.3でうまく動作します。