-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalarm_controller.py
More file actions
53 lines (47 loc) · 1.58 KB
/
alarm_controller.py
File metadata and controls
53 lines (47 loc) · 1.58 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
import subprocess
import os
import signal
class AlarmController:
def __init__(self, video_path: str, volume: int = 100):
self.video_path = os.path.abspath(video_path)
self.volume = volume
self.process = None
def play(self):
if not self.is_playing():
# Open, autoplay, and set volume with QuickTime using AppleScript
script = f'''
tell application "QuickTime Player"
open POSIX file "{self.video_path}"
set audio volume of document 1 to 1.0
play document 1
end tell
tell application "System Events"
set volume output volume 100
end tell
'''
self.process = subprocess.Popen(
["osascript", "-e", script],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
def stop(self):
if self.process:
# Kill QuickTime Player
subprocess.run(
["osascript", "-e", 'quit app "QuickTime Player"'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
self.process = None
def is_playing(self) -> bool:
if self.process is None:
return False
# Check if QuickTime is still running
result = subprocess.run(
["pgrep", "-x", "QuickTime Player"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
return result.returncode == 0
def cleanup(self):
self.stop()