# 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:** 12\
**Page:** 3

<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 7, 2020, 7:32am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/43 "2020-06-07T07:32:56Z")

</div>

> [@Future\_Face](#):
>
> ![ghfgvjh](https://community.folivora.ai/uploads/default/original/2X/5/56b93e523bb61325d035144c90d6b3da05eafa12.png)

You have to run it every now and then… 😃 Something like every 60sec or so should be fine for the battery. Also, do **not** place this widget inside a group, as the group would prevent running the script for performance and energy reasons as long as the group is not open.

---

<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, 7:54pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/44 "2020-06-07T19:54:23Z")

</div>

> [@Caliguvara](#):
>
> Also, do **not** place this widget inside a group,

wait so untick 'show in amy open group'?

---

<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 7, 2020, 8:34pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/45 "2020-06-07T20:34:29Z")

</div>

No, this has to stay. But the widget itself has to remain in the main section, not put inside a folder. "Always display" is perfect.

---

<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, 9:05pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/46 "2020-06-07T21:05:45Z")

</div>

the red bar is still activating when its not below 10%  
coding:

```
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"
		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 9, 2020, 9:12pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/47 "2020-06-09T21:12:12Z")

</div>

bump..

---

<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 10, 2020, 4:50am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/48 "2020-06-10T04:50:39Z")

</div>

> [@Future\_Face](#):
>
> the red bar is still activating when its not below 10%

I don't know why. You get some text in it too?

---

<div class="post-metadata">

**Author:** ![rishifter](https://community.folivora.ai/user_avatar/community.folivora.ai/rishifter/32/11656_2.png) [@rishifter](https://community.folivora.ai/u/rishifter)\
**Post date:** [June 10, 2020, 6:26am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/49 "2020-06-10T06:26:35Z")

</div>

My battery went to 10% reading all these replies! 😂

---

<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 10, 2020, 6:41am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/50 "2020-06-10T06:41:44Z")

</div>

nope...

---

<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 10, 2020, 7:29am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/51 "2020-06-10T07:29:12Z")

</div>

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

Works fine here. Guess you have some strange settings/behaviour in the widget setup itself. But that's not script related.

---

<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 11, 2020, 11:30pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/52 "2020-06-11T23:30:52Z")

</div>

hmm, weird. it was working while on 10%, but not anything below that (9%, etc)  
and also, my Mac is currently on 16% and the red strip without text is coming up on touchbar

---

<div class="post-metadata">

**Author:** ![youngdrippyrich](https://community.folivora.ai/user_avatar/community.folivora.ai/youngdrippyrich/32/11871_2.png) [@youngdrippyrich](https://community.folivora.ai/u/youngdrippyrich)\
**Post date:** [July 13, 2020, 4:37pm UTC](https://community.folivora.ai/t/battery-triggered-button/16321/53 "2020-07-13T16:37:34Z")

</div>

Just used your guys' long ass conversation to implement this warning to my own Touch Bar. Thanks so much to you to for working this through!

---

<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:** [July 14, 2020, 5:32am UTC](https://community.folivora.ai/t/battery-triggered-button/16321/54 "2020-07-14T05:32:48Z")

</div>

its working for you? dang. lol

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