Is there a way (maybe through a variable) to check if any sound (music, video playing, notification, etc) is currently playing at the moment a macro is triggered?
My goal is to trigger a macro with a shortcut but cancel it (or do something else) if a sound is playing.
Hi, ccstone! Thank you for your response. It works but it delays. Do we have a better way to solve the problem? PS: I've tried to replay the post above, but I'm not qualified enough to replay it.
I take it you actually mean it took a few seconds after pausing for the answer to be "No" rather than the script was delayed in its execution (which certainly shouldn't happen!). AFAIK there's no way round that, it's the way CoreAudio and pmset behave.
Perhaps you could explain what you want to achieve? The "better way to solve the problem" might be to attack it from a different angle.
That's a good question. I want a video of a YouTube page on a Chrome browser auto full screen if it's playing when switching to the browser. But it didn't work well when the delay occurs ▼
The macro I created is as below:
Test Macro (v10.2) Test.kmmacros (6.8 KB)
If you use a local variable you won't have to delete it at the end of the macro. You only care if a video is playing if the front window is Youtube, so test the front window first so you aren't running the shell script unnecessarily. The expression you are using to test the URL looks strange to me, but perhaps you are getting a different URL via a proxy service or similar -- I've used what works for me.
On my machine (M1 Air running Ventura) Core Audio seems to be running all the time (probably an issue with my setup). But when Chrome is playing a video it prevents sleep, so I've used that in the test instead -- that also seems to "release" quicker than Core Audio when I pause the video. I've added a dialog at the end to show how long the macro takes to run plus the result of the test, in case you need it for troubleshooting.