-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
39 lines (34 loc) · 1.17 KB
/
main.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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import rumps
import subprocess
rumps.debug_mode(True)
class CaffeineApp(rumps.App):
@rumps.clicked("caffeinate?")
def toggle(self, sender):
if not sender.state:
try:
self.caffeine_proc = subprocess.Popen(["caffeinate", "-d"])
sender.state = not sender.state
except Exception as e:
print(e)
else:
try:
if self.caffeine_proc:
self.caffeine_proc.kill()
self.caffeine_pro = None
sender.state = not sender.state
except Exception as e:
print(e)
self.title = "📺🔒" if sender.state else "📺🔓"
@rumps.clicked("exit")
def quit(self, sender):
if isinstance(self.caffeine_proc, subprocess.Popen):
self.caffeine_proc.kill()
rumps.quit_application(sender)
def __init__(self, *args, **kwargs):
super(CaffeineApp, self).__init__(*args, **kwargs)
self.quit_button = None
self.caffeine_proc = None
if __name__ == "__main__":
CaffeineApp("📺🔓").run()