# Battery-triggered Button

**URL:** <https://community.folivora.ai/t/battery-triggered-button/16321>\
**Category:** Configuration Help & General Discussion\
**Created:** [May 20, 2020, 3:38am UTC](https://community.folivora.ai/t/battery-triggered-button/16321 "2020-05-20T03:38:32Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [May 26, 2020, 11:55pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/23 "2020-05-26T23:55:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [May 27, 2020, 8:05am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/24 "2020-05-27T08:05:04Z")

</div>

```
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.

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [May 27, 2020, 8:07am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/25 "2020-05-27T08:07:10Z")

</div>

> [@Future\_Face](#):
>
> Also, is there a way for it to completely cover up my entire touchbar?

> [@Caliguvara](#):
>
> Unfortunately, you can’t make the other buttons on the right “hover” about the red background. You would have to change every button to a widget, which would just be battery consuming as hell.

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

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [May 27, 2020, 9:11pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/26 "2020-05-27T21:11:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [May 27, 2020, 9:25pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/27 "2020-05-27T21:25:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [May 28, 2020, 5:34am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/28 "2020-05-28T05:34:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [May 28, 2020, 7:43am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/29 "2020-05-28T07:43:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [June 3, 2020, 11:03pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/30 "2020-06-03T23:03:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [June 4, 2020, 6:59am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/31 "2020-06-04T06:59:24Z")

</div>

Works fine here. How do you manage all the time to have a messy Apple Script output? 😃  
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 😃

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

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [June 4, 2020, 9:17pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/32 "2020-06-04T21:17:25Z")

</div>

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](https://community.folivora.ai/t/dialog-box-title/16582/13). 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

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [June 5, 2020, 6:29am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/33 "2020-06-05T06:29:52Z")

</div>

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

> [@Future\_Face](#):
>
> 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?

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

 ![Screenshot 2020-06-05 at 09.27.10](https://community.folivora.ai/uploads/default/original/2X/5/5aac79c0dc43d3e50354a4259d9916dc7d2ffdc0.png)  
Don't know though if this would work.

* * *

This said, you really have a phobia of empty batteries 😃

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [June 6, 2020, 1:27am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/34 "2020-06-06T01:27:40Z")

</div>

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

 ![halp](https://community.folivora.ai/uploads/default/original/2X/1/115cccbc331d31072285caf87c01713873ee1d29.jpeg)  
also, I do school at home on my laptop and have had a bad experience with laptop going flat, and not saving work! 😂

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [June 6, 2020, 5:55am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/35 "2020-06-06T05:55:25Z")

</div>

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 😉  
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 😂

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

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [June 6, 2020, 7:57am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/36 "2020-06-06T07:57:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [June 6, 2020, 7:58am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/37 "2020-06-06T07:58:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [June 6, 2020, 8:01am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/38 "2020-06-06T08:01:42Z")

</div>

> [@Future\_Face](#):
>
> 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

```

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [June 6, 2020, 8:11am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/39 "2020-06-06T08:11:12Z")

</div>

alright, tried that. the voice is amazing..prob gonna scare me shitless at some point in the future 😂😂  
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

```

---

<div class="post-metadata">

**Author:** ![Caliguvara](https://community.folivora.ai/user_avatar/community.folivora.ai/caliguvara/32/42570_2.png) [@Caliguvara](https://community.folivora.ai/u/Caliguvara)\
**Post date:** [June 6, 2020, 9:49am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/40 "2020-06-06T09:49:56Z")

</div>

Oh yeah sorry 😂 for test purposes I changed 11 to 99. Change it back and you should be good 👍🏽

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [June 6, 2020, 11:46pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/41 "2020-06-06T23:46:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Future\_Face](https://community.folivora.ai/user_avatar/community.folivora.ai/future_face/32/13410_2.png) [@Future\_Face](https://community.folivora.ai/u/Future_Face)\
**Post date:** [June 7, 2020, 4:27am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/42 "2020-06-07T04:27:14Z")

</div>

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

 ![egggggggg](https://community.folivora.ai/uploads/default/original/2X/b/bf844e258a570e0051b4874bfe17cc702f893d59.png)

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

 ![ersrgxh](https://community.folivora.ai/uploads/default/original/2X/e/eea684138d5eff7c13cab5a746da29a6b1c032f7.png) ![fhgcnvxjh](https://community.folivora.ai/uploads/default/original/2X/b/bbc129dd579c3d32d3b4bb93c060edfada3ad67a.png) ![ghfgvjh](https://community.folivora.ai/uploads/default/original/2X/5/56b93e523bb61325d035144c90d6b3da05eafa12.png) ![vghjk](https://community.folivora.ai/uploads/default/original/2X/3/31d029ee68559f87eff9a38a032d84a0e2a04d71.png)

[Previous page](https://community.folivora.ai/t/battery-triggered-button/16321.md?page=1)

[Next page](https://community.folivora.ai/t/battery-triggered-button/16321.md?page=3)
