Battery-triggered Button

update:
using the code u sent me, it worked. I must have broken something while changing the output to my own one. So can you please update the code to make it, all on one line, say: Warning: X% remaining. Please charge MacBook. X minutes until lockdown.
Note that I don't have an hour until lockdown, just minutes.
Also, is there a way for it to completely cover up my entire touchbar? I think I asked this before, but I don't remember if I did.
thanks so much

set powersource to word 4 of paragraph 1 of (do shell script "pmset -g batt")
if powersource is "AC" then
	return ""
else
	set batteryPercent to word 6 of paragraph 2 of (do shell script "pmset -g batt")
	if batteryPercent is "100" then
		return ""
	else if batteryPercent is less than "11" then
		tell application "BetterTouchTool"
			execute_assigned_actions_for_trigger "PASTE_THE_UUID_HERE"
		end tell
		set remainingminutes to word 9 of paragraph 2 of (do shell script "pmset -g batt")
		return "Warning: " & batteryPercent & "% Remaining. Please charge MacBook. " & remainingminutes & "min until lockdown"
	else
		return ""
	end if
end if

Here you go.

You could try to replace them, but you would run more background processes all the time. The action/benefit ratio isn't really balanced imho

ok that's fine. thanks for your help.. I think we are done (for real this time :D)
thanks

oh doesn't matter. it worked, then I tried to change the extra padding inside, and BTT crashed. now it won't work at all, even after re-copy-and-pasting the code you sent again.
If you can't help me at this point, that's fine.
thanks for the time you spend helping me, not just with this particular addition, but with everything else.

Run it in the Script Editor to see wether there is any script internal bug. Afterwards the easiest thing might be to make a new widget, to "remake" it. Probably BTT had a hiccup there.

ahh i just tried to remake it, and it worked.
thanks

weird thing that's happened...
now the code only works while batter is on 10%
this is the code:

set powersource to word 4 of paragraph 1 of (do shell script "pmset -g batt")

if powersource is "AC" then

return ""

else

set batteryPercent to word 6 of paragraph 2 of (do shell script "pmset -g batt")

if batteryPercent is "100" then

return ""

else if batteryPercent is less than "11" then

tell application "BetterTouchTool"

execute_assigned_actions_for_trigger "1F9B1FAB-8AA0-4005-B330-FE5E6B8FA6A0"

execute_assigned_actions_for_trigger "8D546CE9-7950-4AA8-806F-983A322BD4A2"

end tell

set remainingminutes to word 9 of paragraph 2 of (do shell script "pmset -g batt")

return "Warning: " & batteryPercent & "% Remaining. Please charge MacBook. " & remainingminutes & "min until lockdown"

else

return ""

end if

end if

Btw, the second UUID in there is one for a dialog box to appear. is that the reason why it isn't working at 9% and lower now? thanks

Works fine here. How do you manage all the time to have a messy Apple Script output? :smiley:
I honestly don't know why this doesn't work out for you. Theoretically it should. If the second UUID is just a HUD try just to add it as an attached action to the first trigger and delete the second line (execute_assigned_actions_for_trigger "8D546CE9-7950-4AA8-806F-983A322BD4A2") from the script. Maybe this would make it work. If it only got buggy once you added that line, then yes the bug is due to it :smiley:

Nevertheless: it happens that I have some troubles with Apple Script Widgets after editing them. I guess you already tried to restart BTT?

I don't understand what you mean by 'just add it as an attached action to the first trigger and deleting the second line'? please elaborate?
Yes I've tried restarting BTT. I'm getting help for the dialog box here: Dialog Box Title. he said to put the uuid in the same script. do you have any other options for both the touchbar warning and the dialog box to appear?
thanks

Tested it again, works perfectly fine. Maybe make a new widget again?

To make something like this for your triggered UUID (replace HUD with apple script to get your message):


Don't know though if this would work.


This said, you really have a phobia of empty batteries :smiley:

2 Likes

ok, I don't quite know what to do from here...


also, I do school at home on my laptop and have had a bad experience with laptop going flat, and not saving work! :joy:

Give the HUD a title (Battery!) and maybe a text below like 10% Remaining!!, and maybe give it a duration to display of more than 0.9sec :wink:
This said, with the Touch Bar, the haptic feedback and if you want I can also make your laptop say it you should be fine :joy:

Not saving work?? Using Microsoft office or what happened??

ok ill try that, thanks

I use google docs mainly which obv has auto save, but I use word too. I don't use autosave on word because it causes some weird problems on my laptop.

and how do I make the new idea only come up when there's 10% remaining?

The speaking? Insert the following line before the "return" line:

say "Warning: " & batteryPercent & "% Remaining. Please charge MacBook. " & remainingminutes & "min until lockdown" using "Alex" with stopping current speech without waiting until completion

(Attention tu use a voice you downloaded)

set powersource to word 4 of paragraph 1 of (do shell script "pmset -g batt")
if powersource is "AC" then
	return ""
else
	set batteryPercent to word 6 of paragraph 2 of (do shell script "pmset -g batt")
	if batteryPercent is "100" then
		return ""
	else if batteryPercent is less than "99" then
		tell application "BetterTouchTool"
			execute_assigned_actions_for_trigger "YOUR_UUID_HERE"
		end tell
		set remainingminutes to word 9 of paragraph 2 of (do shell script "pmset -g batt")
		say "Warning: " & batteryPercent & "% Remaining. Please charge MacBook. " & remainingminutes & "min until lockdown" using "Alex" with stopping current speech without waiting until completion
		return "Warning: " & batteryPercent & "% Remaining. Please charge MacBook. " & remainingminutes & "min until lockdown"
	else
		return ""
	end if
end if

alright, tried that. the voice is amazing..prob gonna scare me shitless at some point in the future :joy::joy:
but it's still happening even when the % is not 10 or less...

this is my code:

set powersource to word 4 of paragraph 1 of (do shell script "pmset -g batt")
if powersource is "AC" then
	return ""
else
	set batteryPercent to word 6 of paragraph 2 of (do shell script "pmset -g batt")
	if batteryPercent is "100" then
		return ""
	else if batteryPercent is less than "99" then
		tell application "BetterTouchTool"
			execute_assigned_actions_for_trigger "1F9B1FAB-8AA0-4005-B330-FE5E6B8FA6A0"
		end tell
		set remainingminutes to word 9 of paragraph 2 of (do shell script "pmset -g batt")
		say "Warning: " & batteryPercent & "% Remaining. Please charge MacBook. " & remainingminutes & "min until lockdown" using "Alex" with stopping current speech without waiting until completion
		return "Warning: " & batteryPercent & "% Remaining. Please charge MacBook. " & remainingminutes & "min until lockdown"
	else
		return ""
	end if
end if

Oh yeah sorry :joy: for test purposes I changed 11 to 99. Change it back and you should be good :+1:t4:

1 Like

alright, guess ill just wait for 10% to come around...

update:
the red bar is going on my touchbar even when its not below 10%

The HUD or the voice isnt working unless i press run script
heres my settings for it...