-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgosd_go.py
executable file
·31 lines (29 loc) · 1 KB
/
gosd_go.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
#!/usr/bin/env python
# gosd_go.py - Show, toggle, or hide the OSD.
# With a dash as the sole argument, it will send the text read from stdin to the OSD to display it.
# Arguments other than "-" or "osd" are treated as text to be displayed by the OSD.
# Returns 0 on success, 1 if attempting to hide an already-hidden OSD, 2 on timeout, or 3 on some other type of error.
import sys, socket
if __name__ == '__main__':
s = socket.socket()
s.settimeout(4)
try:
s.connect(('localhost', 9876))
if len(sys.argv) > 1:
if sys.argv[1] == '-':
s.send(bytes(sys.stdin.read(), 'utf-8'))
elif len(sys.argv) == 2 and sys.argv[1] == 'osd':
s.send(bytes("SHOW\n", 'utf-8'))
else:
txt = " ".join(sys.argv[1:])
s.send(bytes(txt, 'utf-8'))
else:
s.send(bytes("SHOW\n", 'utf-8'))
response = str(s.recv(10), 'utf-8').rstrip()
s.close()
exit(int(response))
except TimeoutError:
exit(2)
except Exception as e:
print("Caught error: " + e)
exit(3)