Skip to main content
Today-Scripts

Today-Scripts #

This programme stopped working after upgrading to macOS 10.12 (Sierra). I collect these scripts here only for future reference purpose.

Refs:

Battery status #

full=$(pmset -g batt | { read; read n full; echo "$full"; })
batt=$(echo "$full" | awk '/(%);/{print $2}' | cut -d'%' -f1)
status=$(echo "$full" | cut -d';' -f2 | tr -d ' ')
time=$(echo "$full" | awk '/(%);/{print $4 " " $5}') #cut -d';' -f3 | sed 's/^ *//'
noc=$'\e[39m'


if   (($batt >= 66)); 
then battc=$'\e[32m';
elif (($batt >= 33)); 
then battc=$'\e[33m';
else battc=$'\e[31m';
fi;

if [ "$status" == "discharging" ]; then
    statc=$'\e[31m';
elif [ "$status" == "charging" ]; then
    statc=$'\e[32m';
elif [ "$status" == "charged" ]; then
    statc=$'\e[32m';
else
    statc=$'\e[33m';
fi

cyc_count=`ioreg -w0 -l | grep "Cycle Count" | awk 'BEGIN { FS = "=" } ; {print $8}' | awk 'BEGIN { FS = "}" } ; {print $1}'`

echo "$battc$batt%$noc"
echo "$statc$status$noc"
echo "$time" 
echo "$cyc_count cycles"

IP address #

echo -e "Local:    \c"
ipconfig getifaddr en0
echo -e "Gateway:  \c"
netstat -rn | grep default | grep en0 | awk '{print $2}'
echo -e "Public:   \c"
curl icanhazip.com

Time zones #

echo "Shanghai    `export TZ='Asia/Shanghai';date +'%H:%M';unset TZ`"
echo "Tokyo       `export TZ='Asia/Tokyo';date +'%H:%M';unset TZ`"
echo "Los Angeles `export TZ='America/Los_Angeles';date +'%H:%M';unset TZ`"
echo "Bonn        `export TZ='Europe/Berlin';date +'%H:%M';unset TZ`"