-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
45 lines (38 loc) · 1.36 KB
/
utils.py
File metadata and controls
45 lines (38 loc) · 1.36 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
import os
import psutil
import win32gui
import win32process
from datetime import datetime, time as dt_time
def is_time_between(start_time, end_time, check_time=None):
"""Check if current time is between start and end time"""
# If check time is not given, default to current time
check_time = check_time or datetime.now().time()
# Handle case where start is after end (spans midnight)
if start_time <= end_time:
return start_time <= check_time <= end_time
else: # Over midnight
return check_time >= start_time or check_time <= end_time
def get_active_window_process():
"""Get the process name of the currently active window"""
try:
# Get handle of active window
hwnd = win32gui.GetForegroundWindow()
# Get PID from window handle
_, pid = win32process.GetWindowThreadProcessId(hwnd)
# Get process name from PID
process = psutil.Process(pid)
return process.name()
except:
return None
def is_app_running(app_names):
"""Check if any of the specified apps are running"""
if not app_names:
return False
try:
# Get all running processes
for proc in psutil.process_iter(['name']):
if proc.info['name'] in app_names:
return True
return False
except:
return False