-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbluetoothloop.py
More file actions
26 lines (25 loc) · 1.22 KB
/
bluetoothloop.py
File metadata and controls
26 lines (25 loc) · 1.22 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
import subprocess
import time
import signal
def bluetoothLoop():
while True:
time.sleep(5)
sound = "Blow"
title = "TURN OFF BLUETOOTH"
message = "-------------------------"
bluetooth = subprocess.Popen(['''system_profiler SPBluetoothDataType'''], stdout=subprocess.PIPE, shell=True, encoding="utf", errors="ignore")
bluetooth_state = bluetooth.communicate()
if "State: On" in bluetooth_state[0] and not " Connected:" in bluetooth_state[0]:
bluetooth.send_signal(signal.SIGINT)
time.sleep(10)
bluetooth = subprocess.Popen(['''system_profiler SPBluetoothDataType'''], stdout=subprocess.PIPE, shell=True, encoding="utf", errors="ignore")
bluetooth_state = bluetooth.communicate()
if "State: On" in bluetooth_state[0] and not " Connected:" in bluetooth_state:
bluetooth.send_signal(signal.SIGINT)
command = f'''
osascript -e 'display notification "{message}" with title "{title}" sound name "{sound}"'
'''
notify = subprocess.Popen(command, shell=True)
time.sleep(20)
notify.send_signal(signal.SIGINT)
return notify