コマンドが完了したらサウンドを再生

コマンドが完了したらサウンドを再生

ユーザーが開始したコマンドが完了したら端末に警告/音を再生させる効率的な方法は何ですか?

各コマンドの後に「警告音」コマンドを明示的に実行する必要がないように自動でなければなりません。

ベストアンサー1

ビープ音を使用できます。echo -en "\007"MBでスピーカーを使用することは非常に基本的なことであり、サウンドカードも必要ありません。しかし、今ではしばしば無効になります。有効にするには、これを試してみてください。https://superuser.com/a/22769

多くのディストリビューションには PulseAudio があるので、次のように CLI でサウンドを再生できます。paplay /usr/share/sounds/freedesktop/stereo/complete.oga

別のメソッドを作成することもできます。https://askubuntu.com/questions/277215/how-to-make-a-sound-once-a-process-is-complete

【編集】すみません。すべてのコマンドバージョンであなたのバージョンを確認できませんでした。trap必要な動作を達成するために、以前に作成した内容を組み合わせることもできます。https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/

# This will run before any command is executed.
function PreCommand() {
  if [ -z "$AT_PROMPT" ]; then
    return
  fi
  unset AT_PROMPT
}
trap "PreCommand" DEBUG

# This will run after the execution of the previous full command line.  We don't
# want it PostCommand to execute when first starting a bash session (i.e., at
# the first prompt).
FIRST_PROMPT=1
function PostCommand() {
  AT_PROMPT=1

  if [ -n "$FIRST_PROMPT" ]; then
    unset FIRST_PROMPT
    return
  fi

  paplay /usr/share/sounds/freedesktop/stereo/complete.oga
}
PROMPT_COMMAND="PostCommand"

おすすめ記事