1
votes

I wrote an FMX (FireMonkey) application and I want to change (increase / decrease) and mute / unmute the master volume output in OS X. Either in Delphi or C++Builder. Alternatively I would do it by simulating key presses of the specific keys of the keyboard.

For Windows, it is fairly easily by simulating key presses with SendInput() or even easier with keybd_event().

This is how it works on windows for me:

// vkVolumeUp / vkVolumeDown / vkVolumeMute
// VK_VOLUME_UP / VK_VOLUME_DOWN / VK_VOLUME_MUTE
keybd_event(vkVolumeUp, 1, 0, 0);
keybd_event(vkVolumeUp, 1, KEYEVENTF_KEYUP, 0);

But I can't manage to compile it for OS X, since the IDE tells me that it doesn't know this functions. A direct way to change the volume would be even better if it is possible.

1

1 Answers

2
votes

This is probably a long-winded, inefficient way of doing it, but you can mute the volume from the Terminal like this:

osascript -e 'set volume with output muted'

and increase it by 20 notches like this

osascript -e 'set volume output volume ((output volume of (get volume settings)) + 20)'

I presume you could use the system() command to execute those till someone tells you a better way.