FelixKratz / SbarLua

A Lua API for SketchyBar
GNU General Public License v3.0
151 stars 11 forks source link

sbar.exec() working inconsistently #37

Closed Pix-xiP closed 3 months ago

Pix-xiP commented 3 months ago

sbar.exec() appears to only be working with certain options.

I assume I've misunderstand something about it but running:

sbar.exec("lsappinfo info -only StatusLabel 'Slack'", function(result)
-- ....
end)

Works just fine, and I can print out result for something like: "StatusLabel"={ "label"="•" }

However when I run

sbar.exec("pmset -g batt", function(result)
-- ......
end)

I get nothing back from the function and it prints an empty string.

Am I missing something important?

FelixKratz commented 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

Pix-xiP commented 3 months ago

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

Pix-xiP commented 3 months ago

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

FelixKratz commented 3 months ago

You could try the latest commit to see if that has helped, I had a suspicion what could cause this.

Pix-xiP commented 3 months ago

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 ^-^