General TC > Programming & Scripting - Unofficial
acpid scripts for laptop Fn+F2/3/6/7/8 functions
nick65go:
It would be nice if flit.tcz has a nice battery alarm option, like I tried to simulate with crond daemon.Anyway, it works for me now. I had 3 times popup messages about battery 2% - 5%, so it seams that 5 minutes interval has good granularity for not missing the 2%-7% threshold.
Summary (until now) about automation of basic tasks accomplished:
--- Code: ---tc@box:~/.X.d$ ls -al
-rwxrwxr-- 1 tc staff 136 May 20 14:06 flit+alsa
-rwxrwxr-- 1 tc staff 512 May 20 14:54 myacpi
--- End code ---
--- Code: ---tc@box:~/.X.d$ cat flit\+alsa
[ -e /usr/local/tce.installed/alsa ] || tce-load -i -l alsa.tcz
[ -e /usr/local/tce.installed/flit ] || tce-load -i -l flit.tcz
flit &
--- End code ---
--- Code: ---tc@box:~/.X.d$ cat myacpi
# lower brightness, from default 255 to 32
echo 32 | sudo tee /sys/class/backlight/radeon_bl0/brightness &
#start acpid daemon for F2/3(brightness), F6/7/8(sound), and LID
sudo kill `pidof acpid`
sudo /usr/local/sbin/acpid &
#start crond daemon for battery low 2%
sudo kill `pidof crond`
sudo /usr/local/sbin/crond &
#stop orfans daemons (/sbin/udevd --daemon) for firmware
sudo kill `pidof udevd`
#stop wire-network if we use wifi
[ -e /var/run/udhcpc.eth0.pid ] && sudo kill `cat /var/run/udhcpc.eth0.pid`
--- End code ---
So no more multiple/useless acpid, crond, udevd.
Next challenge is to tame the UEFI to boot automatically grub2, instead of the tedious F9 + select UEFI partition + the scrolling for a folder/grub.efi. (for 5-10 seconds faster boot?). Because default is win10 "hard-coded", so maybe to change some efi variables.
curaga:
That is a risky operation on some machines. Changing those EFI vars, on a badly written UEFI BIOS, may cause the machine to become unbootable, and removing the bios battery won't fix it. Do search if your machine has such.
Rich:
Hi nick65go
--- Quote from: nick65go on May 19, 2020, 09:40:59 PM --- ...
--- Code: ---tc@box:~/.acpi$ cat battery.sh
#!/bin/sh
# battery.sh alarm for 2% capacity
LOW=`cat /proc/acpi/battery/BAT0/info | grep "design capacity low:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $LOW
MAX=`cat /proc/acpi/battery/BAT0/info | grep "design capacity:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $MAX
NOW=`cat /proc/acpi/battery/BAT0/state | grep "remaining capacity:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $NOW
[[ $NOW -ge $LOW ]] && exit
[ $NOW -gt `expr $MAX / 50` ] && popup "Battery low `expr 100 \* $NOW / $MAX` %%" && exit
popup "Plug NOW the power cable, Battery is less than 2 %%"
--- End code ---
I do not know if crond (popping up every 5 minutes) will consume itself the battery.
--- End quote ---
Or you could just launch a script in the background that sleeps 99.9999% of the time and occasionally reads the remaining
battery capacity directly:
--- Code: ---#!/bin/sh
# Short script to monitor remaining percent of battery power.
# Check /sys/class/power_supply to find how your battery is named.
#
# Usage:
# BatteryMonitor.sh BatteryName &
#
# Example:
# BatteryMonitor.sh BAT0 &
[ -z "$1" ] && exit
# The percentage that triggers a warning.
WarningLevel=5
# Number of minutes to sleep before checking capacity again.
SleepMinutes=5
PowerPath="/sys/class/power_supply"
BatteryName="$1"
Capacity="$PowerPath/$BatteryName/capacity"
SleepTime=$((60 * $SleepMinutes))
while true
do
sleep "$SleepTime"
RemainingCapacity="`cat $Capacity`"
[ "$RemainingCapacity" -gt "$WarningLevel" ] && continue
popup "Remaining battery capacity is $RemainingCapacity%%"
done
--- End code ---
[EDIT]: The syntax for SleepTime= was corrected in the attachment and this post. See reply #35 and #36. Rich
nick65go:
@Rich: yes, work appreciated! I will try it. I will search for tricks, like /proc/acpi/ vs. /sys/class/power_supply.It was fun to learn for first time how cron works.
@curaga: you are right. It is a big risk, versus the gain, I am still reading about it. Maybe I will get for the fast and dirty solution, to repalce the Win10 bootloader (/EFI/Microsoft/Boot/bootmgrfw.efi, 1.46 MB) with my customized /EFI/1grub.64-gpt.efi (118.5 KB). Made a copy of the former MS bootloader, just to put it back in emergency.
But I suspect that in the background, when I will start Win10, it will silently replace back its bloated boot loader. MS had this bad habit in the past. OR just refuse to boot from grub chain loading.
PS: I do not know if I have a bug in the FLTK environment, it happened in the past also, with TinyCore other versions: During my writing, in editor, but mostly in firefox, my cursor JUMP from current position to random row/position. So if I do not pay attention, I just overwrite previous words. And then I see I wrote crazy phrases/words.
Also, strange things happen with my mouse. I copy an area in aterm with the mouse, by selecting. Sometimes also by right-click mouse after I already selected.
I do not know how to paste it with keyboard, so I just go to destination and just push the mouse middle button for paste.And here the paste is double of my clipboard content, second buffer in the middle of the first buffer.ex: abcde fff hhh -> ababcde fff hhhcde fff hhh
jazzbiker:
--- Quote from: nick65go on May 20, 2020, 03:15:38 PM ---During my writing, in editor, but mostly in firefox, my cursor JUMP from current position to random row/position.
--- End quote ---
Hi, nick65go!
Probably it is the wrong supposition, but looks like accidential touches to the touchpad during typing. Is it possible? Usually, a person, who's typing text, is rather concentrated on the meaning of the process and only the other person can mark those accidential touches.
Some options for {Copy,Paste} for various environments are {Shift-Del,Shift-Ins} {Ctrl-Shift-C,Ctrl-Shift-V}
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version