Closed Pix-xiP closed 3 months ago
This exact function is what I am using in my dotfiles, so for me it is working fine. You receive the exit code of the command if you have installed the latest commit of SbarLua
sbar.exec("pmset -g batt", function(result, exit_code)
-- ......
end)
if there is no battery, or an error with the command it will give a non-zero exit code
Copying that one in and printing the result like so:
sbar.exec("pmset -g batt", function(result, exit_code)
print("BATTERY:", result, "|")
print("EXIT CODE:", exit_code, "|")
end)
I get the following output:
BATTERY: |
EXIT CODE: 0 |
And if I run pmset
manually I get:
Now drawing from 'Battery Power'
-InternalBattery-0 (id=23724131) 100%; discharging; (no estimate) present: true
Very strange, I've updated to latest brew of sketchy and the latest commit of SbarLua with the same behaviour
So I added some prints to the api for debugging:
Battery running
API_PRINTING: ======
CMD: pmset -g batt
4E 6F 77 20 64 72 61 77 69 6E 67 20 66 72 6F 6D 20 27 42 61 74 74 65 72 79 20 50 6F 77 65 72 27 0A 20 2D
49 6E 74 65 72 6E 61 6C 42 61 74 74 65 72 79 2D 30 20 28 69 64 3D 32 33 37 32 34 31 33 31 29 09 38 35
25 3B 20 64 69 73 63 68 61 72 67 69 6E 67 3B 20 38 3A 35 33 20 72 65 6D 61 69 6E 69 6E 67 20 70 72 65
73 65 6E 74 3A 20 74 72 75 65 0A
Callback: 7, exit_code: 0
MSG RETURN: Now drawing from 'Battery Power'
-InternalBattery-0 (id=23724131) 85%; discharging; 8:53 remaining present: true
07 07 00 00 00 00 00 00 00 4E 6F 77 20 64 72 61 77 69 6E 67 20 66 72 6F 6D 20 27 42 61 74 74 65 72 79 20
50 6F 77 65 72 27 0A 20 2D 49 6E 74 65 72 6E 61 6C 42 61 74 74 65 72 79 2D 30 20 28 69 64 3D 32 33 37 32
34 31 33 31 29 09 38 35 25 3B 20 64 69 73 63 68 61 72 67 69 6E 67 3B 20 38 3A 35 33 20 72 65 6D 61 69
6E 69 6E 67 20 70 72 65 73 65 6E 74 3A 20 74 72 75 65 0A
LUA_PRINTING: ======
BATTERY: |
EXIT CODE: 0 |
As far as as the API is concerned, command runs and valid bytes come back and it sends those off, it just does n't seem to fill the result part of the lua api.
Any ideas? Otherwise I'll keep diving into this tomorrow evening
You could try the latest commit to see if that has helped, I had a suspicion what could cause this.
Seems to have made it work, looking at the commit, it wasn't storing state only sometimes?
Am happy to close issue, just for my own curiosity of how it was solved ^-^
sbar.exec()
appears to only be working with certain options.I assume I've misunderstand something about it but running:
Works just fine, and I can print out result for something like:
"StatusLabel"={ "label"="•" }
However when I run
I get nothing back from the function and it prints an empty string.
Am I missing something important?