-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_temp.py
51 lines (43 loc) · 1.48 KB
/
cpu_temp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import rumps
import subprocess
class CpuTemperature(object):
def __init__(self):
self.config = {
"app_name": "MacOS CPU Temperature",
"start": "Check CPU Temperature",
"pause": "Pause Timer",
"interval": 100,
}
self.app = rumps.App(self.config["app_name"])
self.timer = rumps.Timer(self.on_tick, 3)
self.interval = self.config["interval"]
self.set_up_menu()
self.start_pause_button = rumps.MenuItem(
title=self.config["start"], callback=self.start_timer
)
self.app.menu = [self.start_pause_button]
def set_up_menu(self):
self.timer.count = 0
self.app.title = "🌡"
def on_tick(self, sender):
# init count
sender.count = 1
current_temp = subprocess.check_output(["./osx-cpu-temp", "-F"]).decode(
"utf-8", "ignore"
)[:5]
self.app.title = "🌡 " + current_temp + "° F"
sender.count += 1
def start_timer(self, sender):
if sender.title.lower().startswith(("check", "continue")):
if sender.title == self.config["start"]:
self.timer.count = 0
self.timer.end = self.interval
self.start_pause_button.set_callback(None)
self.timer.start()
else:
sender.title = self.config["continue"]
def run(self):
self.app.run()
if __name__ == "__main__":
app = CpuTemperature()
app.run()