-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcpu-temp.py
45 lines (35 loc) · 5.42 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
#!/usr/bin/env python3.7
import iterm2
import re
from subprocess import check_output
def GetTemp():
return check_output(["/usr/local/bin/osx-cpu-temp"]).decode("utf-8").rstrip('\n')
def GetFan():
fans = re.findall(r"(\d{1,4}) RPM", check_output(["/usr/local/bin/osx-cpu-temp", "-f"]).decode("utf-8").replace("\n", " "))
# On Catalina , the fan speed is not yet managed by "/usr/local/bin/osx-cpu-temp" see https://github.com/lavoiesl/osx-cpu-temp/issues/28
if len(fans) >= 1 :
avg = int(sum(map(int, fans)) / len(fans))
return str(avg) + " RPM"
else :
return "Unknown"
async def main(connection):
await iterm2.async_get_app(connection)
icon2x = iterm2.StatusBarComponent.Icon(2, "iVBORw0KGgoAAAANSUhEUgAAACAAAAAiCAYAAAA+stv/AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAlmVYSWZNTQAqAAAACAAFARIAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSATEAAgAAABEAAABah2kABAAAAAEAAABsAAAAAAAAAGAAAAABAAAAYAAAAAF3d3cuaW5rc2NhcGUub3JnAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIgAAAADJGjVWAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAComlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bn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UV5104czEBHXsKLzCAD9Du3gmkGrJvgnfQhBXs4CIBza2Z287jkhvQJSpXg6jZpWnmZ5CQffdZrsvqcqHs1f6JPss95AXeWUvYaw5dopq/QCYR2Rb0KW2tWNBM8Imsio2xq/ZOUAxobbs88n4PC1jCxVYUVWModhaMJsjaODbGuaH4OAEUkzSDoz1zAAAAAABJRU5ErkJggg==")
component = iterm2.StatusBarComponent(
short_description="Temp CPU",
detailed_description="Shows the temperature of the CPU",
knobs=[],
exemplar=GetTemp(),
update_cadence=10,
identifier="com.iterm2.example.cpu-temp",
icons=[icon1x,icon2x])
# This function gets called once per second.
@iterm2.StatusBarRPC
async def coro(knobs, cputemp=iterm2.Reference("iterm2.user.cputemp?")):
return GetTemp() + " ☢ " + GetFan()
# Register the component.
await component.async_register(connection, coro)
# This instructs the script to run the "main" coroutine and to keep
# running even after it returns.
iterm2.run_forever(main)