File size: 1,283 Bytes
0df7e04 036cb0c 0df7e04 036cb0c 0df7e04 036cb0c | 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 subprocess
import os
def open_application(custom_app_name):
"""
Opens common Windows applications based on a user-friendly name.
"""
# Dictionary mapping friendly names to Windows execution commands
apps = {
chrome_path: r"C:\Program Files\Google\Chrome\Application\chrome.exe"
"word": "winword",
"powerpoint": "powerpnt",
"excel": "excel",
"notepad": "notepad",
"calculator": "calc",
"browser": "start msedge" # Opens Microsoft Edge
}
# Normalize the input name
target = custom_app_name.lower().strip()
if target in apps:
print(f"Opening {custom_app_name.capitalize()}...")
try:
# shell=True allows running system aliases like 'winword' or 'calc'
subprocess.Popen(apps[target], shell=True)
print("✅ Application launched successfully.")
except Exception as e:
print("❌ The file path is incorrect. Please verify where the app is installed.")
else:
print(f"❌ '{custom_app_name}' is not in the configured list.")
# Example Usage
if __name__ == "__main__":
# Change this to "powerpoint", "excel", "notepad", or "calculator"
app_to_open = "word"
open_application(app_to_open)
|