aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--example/main.c40
1 files changed, 25 insertions, 15 deletions
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 <stdlib.h>
+#include <sysexits.h>
+
+#include <CoreFoundation/CoreFoundation.h>
-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;
+ }
}