8

Sometimes I turn up the audio on my MacBook, but then forget to turn it back down. Is there a terminal command I could use to detect if audio is currently playing (sound coming from the speakers)?

I need something similar to How to detect that the sound is currently playing in Linux? or Testing if audio devices / sound cards are currently playing?, except that neither of those work as they are for Linux.

1 Answer 1

6

I actually happened to find the answer recently, and I'll post it here for anyone who might need it:

if [[ "$(pmset -g | grep ' sleep')" == *"coreaudiod"* ]]; then echo audio is playing; else echo no audio playing; fi

I discovered the pmset method from this post, but I added some things to it.

2
  • For me it says that audio is playing even thought it was not, only when I closed spotify it said it's not playing Commented Mar 24, 2023 at 13:07
  • @RazLuvaton The command I posted here doesn't work perfectly, but for me it usually says "no audio playing" a few seconds after the audio stops. Technically it's not checking if there is audio, but if the audio driver is preventing the computer from sleeping (even if it's not actively playing anything).
    – htmlcat
    Commented Mar 26, 2023 at 2:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .