File size: 1,140 Bytes
6b33af6 | 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 | import subprocess
import os
def open_application(app_name):
"""
Opens common Windows applications based on a user-friendly name.
"""
# Dictionary mapping friendly names to Windows execution commands
apps = {
"word": "winword",
"powerpoint": "powerpnt",
"excel": "excel",
"notepad": "notepad",
"calculator": "calc",
"browser": "start msedge" # Opens Microsoft Edge
}
# Normalize the input name
target = app_name.lower().strip()
if target in apps:
print(f"Opening {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(f"❌ Failed to open application: {e}")
else:
print(f"❌ '{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)
|