Playing a Sound Until a Condition Is Met?

I want to have a background sound that plays and continues to play until a condition is met. I know there is a play sound, but I do not see a 'stop playing' sound, so I can't use a very long sound that plays once and then shuts off. And I can't see how I could do a repeat loop on a sound and have that run in the background while a macro continues.

What I am trying to achieve is an audio equivalent of a progress bar.

Is this something that I could do in KM?

1 Like

Hi @Lloydi Have a look at the Until and While actions in the wiki and see if they may be what you are looking for.

Thinking out loud here:

  1. Create a macro that just plays a sound in a loop (audio progress bar)
  2. In your macro that you want an audio progress bar you can trigger the audio progress bar macro using action:Execute a Macro [Keyboard Maestro Wiki]
  3. Then once your condition is met you can cancel the audio progress bar macro using actions:Redirect Control Flow [Keyboard Maestro Wiki]

Might be a simple way to reuse the audio progress bar functionality.

What's the sound? The above-mentioned loops will be the way to go for an intermittent alert -- "beep beep beep" -- but you'll have to get creative if you want a continuous tone. You could probably do that by having eg a 1 second loop that plays a 2 second sound clip and setting the "Play" action to "asynchronously" so the sounds overlap.

Here's a (rather irritating!) "warble":

Warble.kmmacros (4.5 KB)


If you are also using the "Display Progress" action you might (totally untested) be able to turn on VoiceOver for the duration, which should announce progress for you.

To be honest I haven’t worked out what sound yet. I was going to create something small like a bleep with a pause and just repeat that as long as needed. I wanted to work out the mechanics first as I thought that it might not be possible. I thought that ‘repeat until’ would only allow me to process what’s inside that repeat block.

I think this may not be what I’m after as I need the sound to start playing (and repeat in a loop) and then, separately, I need to continue running other macros. When it gets to the conclusion of those other steps, the sound should stop.

I just tried to have a macro play a sound that lasted 1 minute. Then I put some test messages afterwards with pauses in between.

What I was hoping would happen:

  • Audio starts
  • Messages start appearing while audio continues playing
  • Audio stops when it reaches end of WAV (OR I trigger 'Kill all Macros')

What actually happened:

  • Audio starts
  • Audio continues for another minute ...
  • Audio stops when it reaches end of WAV
  • Messages start appearing

This is an example of what @cfriend and @MikeTheClicker were getting at. When "Beep Controller" runs it sets a global variable to 1 then runs "Beeping" asynchronously. "Beeping" beeps once per second for as long as the global remains 1.

"Beep Controller" continues, throwing a prompt for you to respond to -- once you do, and you can wait as long as you want, the global is set to 0 so "Beeping" stops. "Controller" then throws another prompt/response to show it is still running.

Beep Contoller.kmmacros (6.6 KB)
Beeping.kmmacros (2.2 KB)


Beep Controller:



OK, I will take a look/listen to that. By the sounds of things (no pun intended) this is precisely what I was aiming for. Thank you!

Get funky -- set a variable at the start of "Beeping", use that for the pause time, then reduce it a tiny bit in every turn through the loop. You'll get a steady speeding up of the beeps, adding to the sense of jeopardy!