Skip to content

Instantly share code, notes, and snippets.

@mbierman
Last active August 11, 2022 02:10
Show Gist options
  • Select an option

  • Save mbierman/af96ef30445f0359e2d91bb7e2c184ad to your computer and use it in GitHub Desktop.

Select an option

Save mbierman/af96ef30445f0359e2d91bb7e2c184ad to your computer and use it in GitHub Desktop.
Uses osx-cpu (https://github.com/lavoiesl/osx-cpu-temp) to get temp and fanspeed. Using LaunchAgent, run every 5 minutes, log to a file
#!/usr/bin/env bash
MACH=$(hostname -s)
tool="$HOME/Documents/Applications/bin/osx-cpu-temp"
if [ ! -f ${tool} ]; then
echo -e "\n\nSorry, you need to install osx-cup-temp on \"$MACH\" for this to function.\n Check https://github.com/lavoiesl/osx-cpu-temp\n"
exit
fi
date=$(date +"%m-%d-%Y %T")
# Set to the location where you store the output. in this case, this directory syncs to Google Drive.
templog="/Volumes/GoogleDrive/My Drive/raw temp/report.csv"
Ctemp=$($tool -C)
Ftemp=$($tool -F)
fan=$($tool -f | cut -f2 -d' ')
CtempClean=$($tool | sed -e 's/.[0-9]°C//g')
FtempClean=$($tool -F | sed -e 's/.[0-9]°F//g')
echo "$date | $Ctemp | $Ftemp | $fan" | sed -e "s/rpm//g" -e "s/°F//g" -e "s/°C//g" -e "s/ | /|/g" | tr '|' ', ' >> "$templog"
if [ "$1" = "debug" ] | [ "$1" = "d" ]; then
echo "$date | $Ctemp | $Ftemp | $CtempClean | $FtempClean | $fan"
elif [ "$1" = "collect" ] | [ "$1" = "c" ] ; then
cat "$templog" | pbcopy
rm "$templog"
elif [ "$1" = "update" ] | [ "$1" = "u" ] ; then
launchctl unload $HOME/Library/LaunchAgents/com.gettemp.plist
sleep 3
launchctl unload $HOME/Library/LaunchAgents/com.gettemp.plist
launchctl load -w $HOME/Library/LaunchAgents/com.gettemp.plist
launchctl load -w $HOME/Library/LaunchAgents/com.gettemp.plist
fi
if [ "$CtempClean" -ge "65" ]; then
echo " 🔥🔥🔥 HOT 🔥🔥🔥"
if [ "$1" != "d" ]; then
osascript -e 'display notification "'$Ftemp' | '$Ctemp' \n'$fan' " with title "🔥 '$MACH' 🔥"'
# curl https://api.pushbullet.com/api/pushes -u TOKEN_REMOVED: -d type=note -d title="$MACH is 🔥: $Ctemp/$Ftemp Fan:$fan" -d body="🌡$Ctemp 🌡$Ftemp $fan" -X POST > /dev/null
fi
else
echo " ⛅️⛅️⛅️ cool ⛅️⛅️⛅️"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment