How to increase the volume for the sound from KM without changing browser or media player volume?

I have pop ups set up to appear at various times of the day. If I am typing, it might create unncessary/wrong inputs for the pop up that appeared unexpectedly.

So, for each pop up I keep a buffer time of 1 second. i first use 'Play sound' KM action which alerts me. Then there is 1 second gap and then the pop up pops up.

Problem is, if the system volume is low, the sound played by KM macro, might not be heard.

So if I put an action that would set system volume to certain level before the KM sound action, it might solve the issue but if I am watching a video or listening to something, it might unnecessarily increase the volume which might startle me due to being too loud.

Any solution? Ideally i would want the submarine sound to be played at specific volume but it should not change the current volume of the video, audio that I am playing in any other app.

Rather than playing a sound, how about using the Display text large? That would notify you a little less painlessly than a submarine.

Incidentally, I keep forgetting to plug my macbook into the power supply , so I have a simple chron job as follows

Every 15 minutes
then display text large "On Battery"

which does the trick.

@jonathonl's suggestion is very sensible, and probably a better approach than what I am sharing here. But inspired by your request I made the subroutine below, it increases the system volume for the duration of the sound notification – only if theres no audio already outputting – otherwise it just plays the notification sound at current volume.
It's a bit crudely done, and not really what you requested, I know, but it kind of works and will at the very least spare you from those startles.

Play sound notification at set volume- if sound is not already outputting DEMONSTRATION v1.1.kmmacros (2.7 KB) (v11.0.2)

Play sound notification- at set volume if sound is not already outputting SUBROUTINE v1.1.kmmacros (17 KB) (v11.0.2)

Macro Images

Edit: Must also direct rightful credit to @cdthomer and @ComplexPoint for creating the scripts I've used, that I got from the threads Sound is not running for specific time” trigger and Set system volume via script/KM variable

Edit2: Altered one mistitled variable within the subroutine

Edit3: Updated the macros as I realised that also local variables can be accessed by scripts

1 Like

These days, FWIW, rather than running the JS in a shell script action, I might
EITHER execute an XML version of the Keyboard Maestro action, customised at run-time:

Expand disclosure triangle to view JS source
Application("Keyboard Maestro Engine")

OR use the Standard Additions method directly in an Execute JavaScript for Automation action. (Access to KM variable values has become much more direct and effortless in Keyboard Maestro 11)

Expand disclosure triangle to view JS source
    {includeStandardAdditions: true}
    {outputVolume: kmvar.local_OutputVolume}

To test either or both of the two actions above:

System volume set from KM variable.kmmacros (4,2 Ko)


The problem is that application volumes aren't usually absolute -- they're relative to System volume. So to do what you want you'd have to reduce the app volume while increasing System volume, play your sound, then increase app volume while reducing System. That's a lot of work!

Better, if you can, to set the System volume to the level you want to hear alerts at and then set your app volumes to a lower level -- that way the alert will break through without your app volumes being changed. You can then vary the apps (like when there's a quiet video) individually or manage the whole lot (when everyone else is asleep) with System volume.

Thanks for sharing these updated approaches to your script, and also for making me realise that I've been wrong in assuming that local variables cannot be accessed by a script!
But testing the different approaches here on my system your old approach is actually the fastest, on average about 0.1s faster than the XML version, and about 0.4s faster than the Standard Additions version. Why might this be?

System volume set from KM variable TESTBED.kmmacros (6.0 KB)

Macro Image

Here also sharing my little MacroTimer submacro, used in the testing above:

MacroTimer Simple – SUBMACRO v1.3.0.kmmacros (4.0 KB)

Macro Image

Edit: Re-uploaded the macro images with more appropriate widths

Less overhead – I imagine the others boil down to shell command lines in the end.

Just a balance between maintainability (human time – expensive) and execution (machine time – cheap).

1 Like

Hello @fluid_eye :wave:

Nige has pointed to something substantial in his post.

Application Sounds as well as System Sounds have a relative volume level.

If you’d really want to have success increasing Sounds for Keyboard Maestro‘s Notifications without changing any other volume level setting and using a Mac with Monterey or higher I suggest you to look for SoundSource by Rogue Amoeba. Thanks to its Shortcuts Support you’ll be able to accomplish this task of temporarily increasing or decreasing the volume Level of each Application to your liking and have always other settings based on your workflow.

I know that this Application is not cheap… but it’s worth doing the investment.

Greetings from Germany



I started using this :+1:

1 Like

this would take away focus from the app that i am using. Might add up to the frustration.

I didn't understand this

Most (maybe all?) app volumes are relative to they System volume. If YouTube is playing at 50% and your System volume is set to 50%, what you hear from YouTube is at 25% of maximum possible volume.

Set your System volume to a comfortable level for alerts, notifications, etc. Then set your app volume so that when the app is playing "normally" you can still hear alerts over the top of it. Since app sound levels can change -- a YouTube video may be quieter than "normal" -- have macros that allow you to raise or lower the app volume as required, without changing the System volume.

Use System volume changes when you want overall volume changes -- I'll increase mine when everyone's out, decrease when they're all in bed -- and that'll change both your alert and app volumes for you.

Simple example -- my current System volume is at 75% (on my own today), Music is at 50%. I'm rocking out to Panama, but can still hear notifications over the top. If a quieter track comes up then

...and if the next is louder:

(No triggers because they're called directly from Stream Deck buttons.)

And when my better half comes home couple of presses of the keyboard volume buttons will take things down to a level that won't disturb her, while maintaining the difference between Music and alerts.

We use lot many apps. how do we do this for each app than outputs audio?
Would one set of action work for each app or we'll have to do make new macro for each app?

You don't have to do it for any apps -- you can use their GUI volume controls. I've done it for Music because that's usually buried under a bunch of other app windows and it's quicker and easier to punch the Stream Deck button than to go searching -- I haven't done it for YouTube (yet) because if I'm watching a video it'll be frontmost and easy to adjust with the player's volume control.

If I did want to use a macro for YouTube it would be via the "Execute JavaScript in Browser" action, using something like

var vid = document.querySelector('.video-stream');
vid.volume = vid.volume - 0.1;

...but I'll defer to the Forum's JavaScripters on that one!

If you are constantly fiddling with app volumes anyway, you've probably already got macros to do that -- just use those.

And if you really want to go crazy with individual app volume control, look at @johns's suggestion of SoundSource over in this thread.

1 Like

It is scriptable via 'Shortcuts' (which obviously could be called by KM)

My earphone is defected.

I hear more volume on the right side. Until I get a chance to get them replaced, I had balanced the mac output in such a way that it would balance the volume in both ears.
so I had shifted the pointer a little towards left.

When I run this macro each time, it brings the pointer in the middle.

This option can be found in System settings > Sound > Output & Input

Any solution?

Your earphones situation definitely makes things a little more complicated. I am absolutely sure it must be possible to solve, somehow, but I am not sure exactly how. And as I believe the solution would rely on more scripting I sadly do not think I can be of much assistance.

But the way I see it the solution could either be a version of @ComplexPoint’s JXA-script that if possible changes volume without resetting balance. Or the more bodgy fix would be to store the audio balance setting at the beginning of the macro (probably relying on a scripted poll alongside, or replacing, the SYSTEMVOLUME() action), and then reinstate this balance setting again at the end of the macro (again probably relying on a scripted solution) — But this is quickly starting to get quite bulky, so hopefully someone will be able to help you towards a more elegant solution than this.

On my Sonoma system, at least, you can't set the balance with AppleScript UI scripting. But you can get the position of the slider bar UI element, you can get the length, and you can work out from those where to get KM to click on the screen to set the balance to your desired level.

Set your required balance in the first "Set..." action, and add a "Quit System Settings" at the end of the macro once you're happy with it.

Set Sound Balance.kmmacros (7.4 KB)


When it comes to resetting the balance to the mid-point you could make another macro based on this, you could have two triggers on this one and an "If Then Else" based on %TriggerValue%, you could start the macro with another AppleScript to get the current value and toggle the new one accordingly. Lots of options, easy to implement with what you already know.

damn this is some high level stuff for me. I wouldn't be able to create such a macro. I gotta learn this from you someday. May be i'll tag this post of your again to ask specific questions about the steps.

meanwhile, I got this error.
Screenshot 2024-04-02 at 8.53.55 AM

Can anything be done?

Apple do keep moving stuff around in System Settings. What version of macOS are you running?