kyleneideck / BackgroundMusic

Background Music, a macOS audio utility: automatically pause your music, set individual apps' volumes and record system audio.
GNU General Public License v2.0
16.22k stars 675 forks source link

Programatically interacting with Background Music (such as through a CLI) #591

Open thiagoeh opened 2 years ago

thiagoeh commented 2 years ago

My end objective is to able to have a timer that automatically adjust the volume of an specific application on Background Music. Instead of directly asking for this feature, which maybe put at low priority and never be implemented, I would to do a feature request for a way to programatically adjust the volume for a single application. Maybe something such as a CLI interface (for which I would build a simple shell script to implement the timer and final command to adjust the volume).

My use case is to be able to temporarily mute an application (such as a live streaming), and unmute it after some minutes (to check if there is some relevant audio being streamed).

This is possibly a duplicate of https://github.com/kyleneideck/BackgroundMusic/issues/278 but I will leave to the maintainers to give a verdict on that.

(Thanks for the project! It's very useful to me).

kyleneideck commented 2 years ago

I think the AppleScript API would work for you. @marcuswu added support for changing app volumes recently. https://github.com/kyleneideck/BackgroundMusic/tree/master/BGMApp/BGMApp/Scripting

plt3 commented 6 months ago

Would it be possible to get an example of how to change the volume of a specific app using the AppleScript API? I also don't have much experience with AppleScript but would love to be able to mute/unmute apps via the command line.

kyleneideck commented 6 months ago

@plt3

    tell application "Background Music"
        set vol of (a reference to (the first audio application whose bundleID is equal to "com.apple.Safari")) to 75
    end tell

You can also use name instead of bundleID.

plt3 commented 6 months ago

Great, thank you!