My macbook air keeps restarting itself, I think it's an energy problem. It displays a restart dialog and if I click in the cancel button, I'm able to continue working, but sometimes it doesn't wait for a confirmation and restarts.
I was thinking of having a macro with a periodic trigger to run every second and click the cancel button.
For instance, the if with button condition doesn't work.
Whilst it is still working, generate a system report which will give you the model number/identifier and your unique machine serial number amongst other things and email the report to a friend.
Then reply to this thread what the model number is.
You do not say whether this is a problem that occurs on mains power or battery power or both, nor how old the machine is.
What you asking for does not seem a good workaround for replacing the battery. It is not too difficult, but depends on the model.
You could also run a hardware diagnostic test on startup with the proviso, backup first if possible.
Just make sure you do everything very very slowly and do not reinstall the operating system by mistake.
I already tried several different approaches (reset smc, boot in safe mode, ...) and multiple reformats. I think it's a hardware issue because the lighning conector doesn't have the led on, the same charger works fine with another macbook.
I've just installed macos high sierra once again so I'd like to prepare this workaround at least to have it functional.
It is your call, of course, but I tend to agree with @jonathonl -- investing your precious time on automating this issue is likely a bad investment. IMO, your Mac could completely crash at any time.
It sounds like a serious problem to me. I would contact Apple support and ask them. Normally I would say take it to an Apple Retail store to the genius bar, but I think their stores are still closed.
I guess the only exception would be if you are stranded somewhere with only that Mac, and you have mission critical work to do. Then, of course, you try to make it last as long as possible, or until you can get Apple support. Or, here's another idea: replace your Mac with a new or used Mac. I've noticed some older Macs going for just a few hundred dollars on eBay.