|
|
Scripts: battery level and nicer uptime
sed is harder to read, but here's more efficient pipeline to show the % battery charge: #!/bin/sh # use sed to print only the line of ioreg's output containing # "Battery", keeping only the values for Capacity and Current; # use bc to calculate 100*Current/Capacity, scaling to # 2 decimal places; format the result using sed ioreg -p IODeviceTree -n "battery" -w 0 | sed -ne \ '/Battery/s@^.*Capacity"=\([0-9]*\),"Current"=\([0-9]*\).*@scale=2; \2\*100/\1@p' \ | bc -l | sed -e 's/\(.*\)/Battery: \1%/' ...and one for uptime: #!/bin/sh # use sed to reformat output from uptime to discard # text preceding and through " up " and text following # and including ", ? users", where ? is 1 or more digits, # then insert the prefix "Uptime: " uptime | sed 's@.* up \(.*\), [0-9]* users.*@Uptime: \1@'
Scripts: battery level and nicer uptime
Hey, where did all the backslashes disappear to? Let's try again: Battery % charge:#!/bin/sh # use sed to print only the line of ioreg's output containing # "Battery", keeping only the values for Capacity and Current; # use bc to calculate 100*Current/Capacity, scaling to # 2 decimal places; format the result using sed ioreg -p IODeviceTree -n "battery" -w 0 | sed -ne \ '/Battery/s@^.*Capacity"=\([0-9]*\),"Current"=\([0-9]*\).*@scale=2; \2\*100/\1@p' \ | bc -l | sed -e 's/\(.*\)/Battery: \1%/'Uptime: #!/bin/sh # use sed to reformat output from uptime to discard # text preceding and through " up " and text following # and including ", ? users", where ? is 1 or more digits, # then insert the prefix "Uptime: " uptime | sed 's@.* up \(.*\), [0-9]* users.*@Uptime: \1@'
Scripts: battery level and nicer uptime
Everything looked OK in preview, but once I hit the "Submit Comment", the backslashes got stripped out. Bleah! |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.13 seconds |
|