From 2226f598a26b9f2943e98ae8d89fd0502b398362 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 27 Oct 2022 01:55:57 +0200 Subject: example/main.c: Get and set volume separately from cmdline args If no arguments are given, print the current system alert volume. If an argument is given, set the alert volume to the given argument. --- example/main.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'example') diff --git a/example/main.c b/example/main.c index 6a851fe..e8e3e31 100644 --- a/example/main.c +++ b/example/main.c @@ -1,25 +1,35 @@ -#include "./lib/SSVLSystemAlertVolume.h" +#include +#include + +#include -int main() { - OSStatus result; +#include "./lib/SSVLSystemAlertVolume.h" +int main(int argc, char *argv[]) { + OSStatus result = noErr; Float32 volume; - result = SSVLGetSystemVolume(&volume); - if (result != noErr) { - printf("Error getting system volume: %d\n", result); - return 1; - } + // Print the current system alert volume when no arguments are given. + if (argc == 1) { + result = SSVLGetSystemVolume(&volume); + if (result != noErr) { + printf("error: can't get system volume: %d\n", result); - printf("System volume: %f\n", volume); + return EX_UNAVAILABLE; + } + printf("%f\n", volume); - Float32 new_volume = 0.5; - result = SSVLSetSystemVolume(new_volume); - if (result != noErr) { - printf("Error setting system volume: %d\n", result); - return 1; + return EX_OK; } - printf("Set volume to: %f\n", new_volume); + // Set the system alert volume to the first argument. + volume = strtof(argv[1], NULL); + + result = SSVLSetSystemVolume(volume); + if (result != noErr) { + printf("error: can't set system volume: %d\n", result); + + return EX_UNAVAILABLE; + } } -- cgit v1.2.3