Trying to find a way for my script to check if there's any sound/audio being played currently on the computer. And if so, is there any way to find which app is playing sound?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Maybe this helps:
One thing that happens when a sound is played is that the power management blocks the computer to go to sleep. With pmset -g
you can see all the Power Management stuff that is going on.
So, when sleep is prevented by "coreaudiod" the machine is playing obviously some sound.
Here what pmset -g
spits out when iTunes is playing:
Currently in use:
womp 0
halfdim 1
sms 1
hibernatefile /var/vm/sleepimage
gpuswitch 2
networkoversleep 0
disksleep 10
sleep 10 (sleep prevented by iTunes, coreaudiod)
hibernatemode 3
ttyskeepawake 1
displaysleep 10
acwake 0
lidwake 1