Change OS X system volume programmatically

前端 未结 3 863
被撕碎了的回忆
被撕碎了的回忆 2020-12-19 13:09

How can I change the volume programmatically from Objective-C?

I found this question, Controlling OS X volume in Snow Leopard which suggests to do:

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 14:07

    You could run a bash script that will change the master volume. This prevents setting the audio first to one side:

    Muted:

    execlp("osascript", "osascript", "-e", "set volume output muted true", NULL);
    

    Change volume (scale 0-10):

        execlp("osascript", "osascript", "-e", "set volume 5", NULL);
    

提交回复
热议问题