aboutsummaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
authorTeddy Wing2022-10-27 01:55:57 +0200
committerTeddy Wing2022-10-27 01:55:57 +0200
commit2226f598a26b9f2943e98ae8d89fd0502b398362 (patch)
treef6f3b69b9f5d518653779682551ec8c945fdf5bb /example
parent2e513617208a8aa3b97107ed2bd1fbb9b5476a30 (diff)
downloadSSVLSystemAlertVolume-2226f598a26b9f2943e98ae8d89fd0502b398362.tar.bz2
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.
Diffstat (limited to 'example')
-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;
+ }
}