A few weeks ago I posted in the forums Tocco, which is a Python utility that is able to grab a good amount of OSX system info. In hopes of speeding things up, I began researching OSX commands that give partial system info and wrote a few bash scripts that some folks in here might find useful.
Do note that the multiline commands can be simply put into one line -- my intention wasn't to make things look obscure. I do not believe there is a feasible way to grab the following out-of-the-box from OSX (but would love to be proven wrong):
- CPU Temperature
Battery Temperature
Note: All of these commands are native to OSX. None of these commands require sudo
. Contributions to this thread are welcomed.
Battery
Percent Left
pmset -g batt | grep "InternalBattery" | awk '{print $3+0"%"}'
Time Left
pmset -g batt | grep "InternalBattery" | awk '{print $5}'
Temperature
Fahrenheit
bc <<< "scale=2; ((($(ioreg -r -n AppleSmartBattery | grep Temperature | awk '{print $3}')/10.0)-273.30) * 9/5) + 32"
Celsius
bc <<< "scale=2; (($(ioreg -r -n AppleSmartBattery | grep Temperature | awk '{print $3}')/10.0)-273.15)"
CPU
Percentage Being Used
/usr/bin/top -ocpu -R -F -l 1 | grep "CPU usage" | awk '{print $3+$5"%"}'
Disk
Percentage Free
df | grep disk1s1 | awk '{print 100-$5"%"}'
Free Disk
df -h | grep disk1s1 | awk '{print $4"B"}'
Used Disk
df -h | grep disk1s1 | awk '{print $2"B"}'
Memory
Replace free
in the grep -w "free"
statement to pull a different values. Available values:
free
inactive
active
speculative
- Others in
vm_stat
command.
Specific
function bth () {
b=${1:-0}; d=''; s=0; S=(B {K,M,G,T,P,E,Z,Y}B)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
echo "$b$d ${S[$s]}"
};
bth $(vm_stat | grep -w "free" | awk '{print $3*4096}')
Bluetooth
Is Device Connected
Change the device_name
to whatever Bluetooth device you have on your computer. Prints either "Yes" or "No."
export device_name="AirPods"
echo $(system_profiler SPBluetoothDataType 2> /dev/null | grep $(echo $device_name) -A 7 | grep Connected) | awk '{if($1==""){print "No"}else{print $2}}'
Network
SSID Name
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep -w SSID | awk '{print $2}'
Network Download Throughput
function bth () {
b=${1:-0}; d=''; s=0; S=(B {K,M,G,T,P,E,Z,Y}iB)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
echo "$b$d ${S[$s]}/sec"
};
function func () {
nettop -L 1 -c -P -x | awK -F "\"*,\"*" '{sum += $5} END {print sum}';
};
export first=$(func);
sleep 1;
export second=$(func);
bth $(expr $second - $first)
Network Upload Throughput
function bth () {
b=${1:-0}; d=''; s=0; S=(B {K,M,G,T,P,E,Z,Y}iB)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
echo "$b$d ${S[$s]}/sec"
};
function func () {
nettop -L 1 -c -P -x | awK -F "\"*,\"*" '{sum += $6} END {print sum}';
};
export first=$(func);
sleep 1;
export second=$(func);
bth $(expr $second - $first)