-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectFactorio.py
More file actions
39 lines (32 loc) · 1.11 KB
/
DetectFactorio.py
File metadata and controls
39 lines (32 loc) · 1.11 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
import psutil
import platform
def is_factorio_running():
"""
Detects if Factorio is currently running on the system.
Returns:
bool: True if Factorio is running, False otherwise
"""
# Different process names on different platforms
factorio_process_names = {
'Windows': ['factorio.exe', 'Factorio.exe'],
'Linux': ['factorio'],
'Darwin': ['factorio', 'Factorio'] # macOS
}
current_os = platform.system()
target_processes = factorio_process_names.get(current_os, ['factorio'])
# Iterate through all running processes
for proc in psutil.process_iter(['name']):
try:
proc_name = proc.info['name']
if proc_name in target_processes:
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
# Process might have ended or we don't have permission
pass
return False
# Example usage
if __name__ == "__main__":
if is_factorio_running():
print("Factorio is currently running!")
else:
print("Factorio is not running.")