Created
November 7, 2025 16:37
-
-
Save bjornpagen/dd1a3a0c8b211c979f10cdffe8ad4e97 to your computer and use it in GitHub Desktop.
Get battery on Asahi Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env lua | |
| local function read_file(path) | |
| local file = io.open(path, "rb") -- r read mode and b binary mode | |
| if not file then return nil end | |
| local content = file:read "*a" -- *a or *all reads the whole file | |
| file:close() | |
| return content | |
| end | |
| local path = "/sys/class/power_supply/macsmc-battery/" | |
| local charge_now = read_file(path .. "charge_now") | |
| local charge_full = read_file(path .. "charge_full") | |
| local percent_left = string.format("%.1f", charge_now/charge_full * 100) | |
| print(percent_left .. "%") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment