Utilities to enable CPU Activity as a touchbar widget
This allows the touchbar to display a graph of the CPU activity over the last 100 seconds by interval of 5 seconds.
This utility simply returns the CPU activity in percent (%) beware that this is the sum of the activity percentage of each of your cores, so if you have 4 cores. Your maximum activity is 400%
This utility add the current CPU activity to the /tmp/cpu.log file and only keep the last 20 entries.
It also prints the content of the file to stdout.
This script reads off the /tmp/cpu.log file, parses it, and generates a graph in heic format at
location /tmp/cpulogimage.heic. It also prints out the JSON file that will be interpreted by BTT
in order to update the icon in the touchbar with the new image.
Since my own laptop has 4 cores I divide the percentage by 400. If you have more (or less) cores you might want to change the "coreCount" variable in this file.
Pull the project with
git pull https://github.com/andrevidela/CPU-Activity-Touchbar.gitThen go into its directory
cd CPU-Activity-TouchbarHere, you can use the install.sh script to symlink those utilities to your location of your preference by giving it
the path as argument. I personally put them in /usr/local/bin. Which means I use the script like that
sh install.sh /usr/local/binIn order for this to work you will need BetterTouchTool and you will have to add a new button in your touchbar.
- First create a new TouchBar trigger
- Select
TouchBar Widgetand thenShell script/Task widget - In the
Scriptfield enter the following program:
cpuHistory > /dev/null
cpuGraphYou can tweak the refresh rate by selecting another time interval.
