SimpleSam commited on
Commit
036cb0c
·
verified ·
1 Parent(s): 9dc1214

Update run_custom_app.py

Browse files
Files changed (1) hide show
  1. run_custom_app.py +35 -7
run_custom_app.py CHANGED
@@ -1,10 +1,38 @@
1
  import subprocess
 
2
 
3
- # Example for Google Chrome using its exact file path
4
- chrome_path = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- try:
7
- subprocess.Popen(chrome_path)
8
- print("✅ Custom application opened.")
9
- except FileNotFoundError:
10
- print(" The file path is incorrect. Please verify where the app is installed.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import subprocess
2
+ import os
3
 
4
+ def open_application(custom_app_name):
5
+ """
6
+ Opens common Windows applications based on a user-friendly name.
7
+ """
8
+ # Dictionary mapping friendly names to Windows execution commands
9
+ apps = {
10
+ chrome_path: r"C:\Program Files\Google\Chrome\Application\chrome.exe"
11
+ "word": "winword",
12
+ "powerpoint": "powerpnt",
13
+ "excel": "excel",
14
+ "notepad": "notepad",
15
+ "calculator": "calc",
16
+ "browser": "start msedge" # Opens Microsoft Edge
17
+ }
18
 
19
+ # Normalize the input name
20
+ target = custom_app_name.lower().strip()
21
+
22
+ if target in apps:
23
+ print(f"Opening {custom_app_name.capitalize()}...")
24
+ try:
25
+ # shell=True allows running system aliases like 'winword' or 'calc'
26
+ subprocess.Popen(apps[target], shell=True)
27
+ print("✅ Application launched successfully.")
28
+ except Exception as e:
29
+ print("❌ The file path is incorrect. Please verify where the app is installed.")
30
+ else:
31
+ print(f"❌ '{custom_app_name}' is not in the configured list.")
32
+
33
+ # Example Usage
34
+ if __name__ == "__main__":
35
+ # Change this to "powerpoint", "excel", "notepad", or "calculator"
36
+ app_to_open = "word"
37
+
38
+ open_application(app_to_open)