-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdark-mode.py
More file actions
82 lines (56 loc) · 1.52 KB
/
dark-mode.py
File metadata and controls
82 lines (56 loc) · 1.52 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import subprocess as sp
import sys
import platform
from os import system
prefix = """osascript -e 'tell application \"System Events\" to tell appearance preferences to"""
get_status = "defaults read -g AppleInterfaceStyle"
def show_help():
help_message = """
Usage: python3 dark-mode.py [command]
Commands
<none> Toggle dark mode
on Enable dark mode
off Disable dark mode
status Dark mode status
"""
print(help_message)
def status():
"""
Get current status, "Dark Mode" or "Light Mode".
"""
try:
status = sp.check_output(get_status.split(), stderr=sp.STDOUT).decode()
status = status.replace("\n", "")
except sp.CalledProcessError:
return "Light Mode"
if status == "Dark":
return "Dark Mode"
def set_mode(mode):
"""
Set the mode
:param mode: The mode to be set
:type mode: str
"""
if mode == "Null":
mode = "not dark mode"
cmd = prefix+" set dark mode to {}'".format(mode)
# I know I should use subprocess but it messes up.
# I will try to fix it.
system(cmd)
def main():
if platform.system() != "Darwin":
print("Can only be run on macOS!")
sys.exit()
if len(sys.argv) == 1:
set_mode("Null")
elif sys.argv[1] == "on":
set_mode("True")
elif sys.argv[1] == "off":
set_mode("False")
elif sys.argv[1] == "status":
print(status())
else:
show_help()
if __name__=="__main__":
main()