show the cpu temperature on the touchbar

download .zip file from this link


you should change some code in this file
image

remove the always loop code


then compile the file
if you execute compile command in terminal in 「~」path
image
image

when you finished

press 「cmd+shift+G」 in 「Finder」, and find the path you executed the command
in my terminal it’s 「~」path

you will find this


it’s in 「~」path in my mac

/Users/guojinchao/temp_sensor

then
change one palce in my script code
replace 「the path your temp_sensor is created」:point_up_2:t2:(check in last step, the path you find the 「temp_sensor」program)


image

BTT:

create a new 「Shell Script/ Task Widget」

==
Launch Path:
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
(my python3 path in my mac, you should replace your own python3 path, I am python 3.6.8)

==
Parameters:
-c

==
Script:
:point_down:t2:



# -*- coding: UTF-8 -*-
import json
import os

def find_cpu_temp(str_name, str_value):
    global i
    list_name = str_name.split(',')
    list_value = str_value.split(',')
    # print(list_name)
    # print(list_value)
    res_l = {}
    for i in range(len(list_name)):
        res_l[list_name[i]] = list_value[i]
    # print(res_l)
    # print(' PMGR SOC Die Temp Sensor0')
    # print(res_l[' PMGR SOC Die Temp Sensor0'])
    try:
        return "CPU:"+ res_l['PMGR SOC Die Temp Sensor0']+" C",float(res_l['PMGR SOC Die Temp Sensor0'])
    except Exception as e:
        return "CPU:"+ res_l[' PMGR SOC Die Temp Sensor0']+" C", float(res_l[' PMGR SOC Die Temp Sensor0'])




global process, output
process = os.popen('「🔥!!!==your_own_path_compile_the_code_up!!!!👈」/temp_sensor')  # return file
output = process.read()
list_output = output.split('\n')
str_name = list_output[0]
str_value = list_output[1]
cpu_temp,float_cpu_temp = find_cpu_temp(str_name, str_value)

process.close()
# print(cpu_temp)



# make json
"""
"{\"text\":\"newTitle\",                                                 
\"icon_data\": \"base64_icon_data\",                                                 
\"icon_path":\"path_to_new_icon\",                                                 
\"sf_symbol_name":\"symbol_name\",                                                 
\"sf_symbol_size":\"size_of_the_symbol\",                                                 
\"background_color\": \"255,85,100,255\",                                                 
\"font_color\": \"100,200,100,255\",                                                 
\"font_size\": 10}"
"""


if float_cpu_temp>70:
    tmp = {
        "text":cpu_temp,
        # "icon_data":"base64_icon_data",
        # "icon_path":"path_to_new_icon",
        # "sf_symbol_name":"symbol_name",
        # "sf_symbol_size":"size_of_the_symbol",
        #"background_color": "226,107,67,255",
        # "font_color": "100,200,100,255",
        # "font_size": 10
    }
    json_str = json.dumps(tmp)
    print(json_str)

elif float_cpu_temp>0:
    tmp = {
        "text": cpu_temp,
        # "icon_data":"base64_icon_data",
        # "icon_path":"path_to_new_icon",
        # "sf_symbol_name":"symbol_name",
        # "sf_symbol_size":"size_of_the_symbol",
        #"background_color": "249,217,96,255",
        # "font_color": "225,225,225,255",
        # "font_size": 10
    }
    json_str = json.dumps(tmp)
    print(json_str)

# elif float_cpu_temp>=0:
#     tmp = {
#         "text": cpu_temp,
#         # "icon_data":"base64_icon_data",
#         # "icon_path":"path_to_new_icon",
#         # "sf_symbol_name":"symbol_name",
#         # "sf_symbol_size":"size_of_the_symbol",
#         "background_color": "101,167,186,255",
#         "font_color": "225,225,225,255",
#         # "font_size": 10
#     }
#     json_str = json.dumps(tmp)
#     print(json_str)

effect:


:smiley:
Any questions can contact me by email:

chaopublic@sina.com
:smiley:


thank you for these links!