How do I tell my system to create a sound alert whenever my battery has charged at least X percent?

Isn’t it just a bash script and bash is present and running anyway already?

But it doesn’t need to make sense to me :sunglasses: that you would like to do it your way from scratch and in C.
Why not …
Have fun doing it!

It was only a rather rhetorical question and just my opinion.

Finally occurred to me to try using ChatGPT to get an example of how to do it in C (was going to get started just now), turns out querying the battery state was as simple as this:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_BUF 64

int main()
{
    FILE *fp;
    char buf[MAX_BUF];

    fp = fopen("/sys/class/power_supply/BAT0/capacity", "r");
    if (fp == NULL) {
        perror("Error opening file");
        return EXIT_FAILURE;
    }

    fgets(buf, MAX_BUF, fp);
    int battery_level = atoi(buf);

    fclose(fp);

    printf("Battery level: %d%%\n", battery_level);

    return EXIT_SUCCESS;
}

Sure I still need to learn how to play the sound file but that’s a task for later, btw just in case anyone here only know of the official site, there’s also this one:

No daily limit but there is a character limit and markdown doesn’t seem to display correctly even if the AI still understands it, also captures enter for the send command which is annoying but still bare-able.

Just an update, didn’t get round to implementing playing sounds directly but I did get round to moving all the unreliable shell code (because of differing standards) that accompanied my little C based application into the application itself.

There’s no longer a need to call watch on it however you may need to adjust the code to suit your needs, I didn’t give it any argument support but I left it in a state where it can easily be added. For now it’s fixed at sleeping for 5min before checking again, it seems to work fine for me anyways, I also gave it a launcher on my desktop because going to it’s folder was a pain.

I gave the sound & notification sections their own little functions so modifying it to use native code instead of deferring to commands via the system call will be easy enough for people/organisations that need/want to do so. It’s set to track via text files in it’s directory - because I started by making it for the watch command before realising I could use the sleep function and only realised just now I shoulda made a buffer - so either mod that yourself before installing or keep it in your user folder/s where it has access to write to it’s cwd.

Edit: btw could admin manually lock this thread now please, I doubt there’s gonna be any more responses of value here, I certainly don’t plan on making any.