Hi All, I've tried to explore this myself in BTT and Shortcuts (not to mention several adventures down rabbit holes in stack overflow) however I'm still a bit stuck so was hoping someone could kindly provide a bit of guidance.
Issue: From time to time my OWC Thunderbolt dock delivers only 15w of charge to my MacBook Pro, not sure why, but something that I'd like to be aware of.
Proposed Solution: I'm setting up a BTT automation that when my screen unlocks, a check is completed on the current charge level and if it is equal to or below 59w (or equal 15w) a notification is shown to let me know.
I'm ok with the automation trigger, with the charge test data generation (shell command below) and how to setup the notification, just need some help with the handling of the charge value test.
This is the test command that I've figured out, that returns the battery charge level in numerical format:
system_profiler SPPowerDataType |grep -i "Wattage" |tail -c 3
Thanks in advance for any help and guidance.
You could probably do something like this using BTT's "run real javascript" action:
(async () => {
let result = await runShellScript({
script:
'/usr/sbin/system_profiler SPPowerDataType |grep -i "Wattage" |tail -c 3',
});
let wattage = parseInt(result);
if (wattage < 60) {
// show a notification if wattage <60
let actionDefinition = {
BTTPredefinedActionType: 371,
BTTPredefinedActionName: 'Show Notification',
BTTAdditionalActionData: {
BTTActionSendNotificationTitle: 'Wattage Too Low',
BTTActionSendNotificationMessage: 'OWC wattage is too low',
BTTActionSendNotificationSound: 'frog',
},
};
let result = await callBTT('trigger_action', {
json: JSON.stringify(actionDefinition),
wait_for_reply: false,
});
}
returnToBTT(wattage);
})();
You just need to define some named trigger in the "automations, named & other triggers section" to show the notification / hud
@Andreas_Hegenberg I'm gobsmacked that you have been so generous as to help me with that code chunk, thank you!
BTT is without question the first app I install on any new Mac, it is the reason that I could move from Windows to Mac all those years ago and is still at the centre of my MacOS.