-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmart Shortcut.py
55 lines (48 loc) · 1.55 KB
/
Smart Shortcut.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import psutil
from AppOpener import open
import time
import threading
debug = False
programs = [
("SrvSurvey.exe", "Srv Survey"),
("Elite Dangerous Odyssey Materials Helper.exe", "EDOMH"),
("EDMarketConnector.exe", "elite dangerous market connector"),
("EDDiscovery.exe", "EDDiscovery"),
("EDDI.exe", "EDDI"),
]
def isProcessRunning(process, running_processes):
'''
Check if the given process is running.
'''
first_letter = process[0].lower()
for running_process in running_processes:
if running_process and running_process[0] == first_letter and process.lower() in running_process:
return True
return False
def openProgram(process, program):
'''
Open a program if it's not already running.
'''
if not isProcessRunning(process, running_processes):
open(program, output=debug)
else:
if debug:
print(program + " already open")
# Get the list of running processes
running_processes = [proc.name().lower() for proc in psutil.process_iter()]
debug = False
if debug:
starttime = time.time()
# Create and start a new thread for each program
threads = []
for process, program in programs:
thread = threading.Thread(target=openProgram, args=(process, program))
thread.start()
threads.append(thread)
# Wait for all threads to finish
for thread in threads:
thread.join()
if debug:
TimeElapsed = time.time() - starttime
TimeElapsedSTR = str(TimeElapsed)
print("runtime " + TimeElapsedSTR )