Please accept my apologies if this offends you.) ioreg -r -k "BatteryPercent" \ (Note: someone who knows perl better than me could probably avoid also needing sed but I barely know any perl so… I'm using sed also. We really don’t needs the words "Product" and "BatteryPercent" or the equal signs. Now the output is: "Product" = "Magic Trackpad 2" "BatteryPercent" = 92 The # are just there to mark the beginning, middle, and end of the perl regular expression. replace it with a " followed by a space (blank).So we add a quick perl line to do that, telling perl only to replace \n if it comes immediately after " and it looks like this: ioreg -r -k "BatteryPercent" \ In perl you can replace a line break by searching for \n. Q: What if we could say “Only remove a line break if it comes immediately after a quotation mark?” Then it wouldn't remove the ones after "92" and "90" because they don't have a quotation mark. The product names are "quoted" but the percentages are not. Q: But how do we say “remove some of the line breaks”? That would be better because we’d know that each device and its percent would be together on the same line. "Product" = "Magic Keyboard" "BatteryPercent" = 90 If we had something like this: "Product" = "Magic Trackpad 2" "BatteryPercent" = 92 Except that the percent is on a different line from the device. ![]() Gives me this result: "Product" = "Magic Trackpad 2" This command: ioreg -r -k "BatteryPercent" \ Here’s an alternative solution that I have used for this. The key to avoiding that is to never trust that ioreg will give you the information in the same order, and deciding what to do about that. If I had to guess (and this is only a guess), I bet that sometimes ioreg is giving you the information in a different order than you are expecting. So the remaining keyboard percentage will be displayed on the mouse Stream Deck key and vice versa. Everything works fine except the 'Local_Mouse' and 'Local_Keyboard' variables randomly seem to switch places.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |