Opening applications by only saying the app name in python
Question:
I just want to open application with only saying the name of the application and not by typing/saying the path or location. Also i want to open application which have their name with spaces like “google chrome”, “snipping tool” etc.
This works with excel, spotify, cmd, notepad and some other programs but does not work with word, powerpoint etc.
elif "start" in text:
app_name = text.strip("start ")
app = app_name
os.system(app)
I just want it to work with two-word applications like google chrome and apps like Word, powerpoint etc.
Answers:
Every executable app running has a one-word name. You can check this by going to the Task manager and tab “details”. There you have all your running programs and their names. For Google Chrome you mentioned it’s “chrome.exe”, for Snipping Tool it’s “snippingtool.exe” etc.
Then it’s easy, you just need to write name of the program and call os.system. Don’t forget the start word there.
app_name = "chrome.exe"
os.system(f"start {app_name}")
I’m not sure which operating system you are on but for Mac OS this code will work for any application wether the name has a space or not.
app_name = text.strip("start ")
app = app_name
os.system("open -a ""+app+""")
Putting the name in quotations allows the use of spaces in the text and the -a
just tells it that you are trying to open an application rather than a file. Hope this helps.
I just want to open application with only saying the name of the application and not by typing/saying the path or location. Also i want to open application which have their name with spaces like “google chrome”, “snipping tool” etc.
This works with excel, spotify, cmd, notepad and some other programs but does not work with word, powerpoint etc.
elif "start" in text:
app_name = text.strip("start ")
app = app_name
os.system(app)
I just want it to work with two-word applications like google chrome and apps like Word, powerpoint etc.
Every executable app running has a one-word name. You can check this by going to the Task manager and tab “details”. There you have all your running programs and their names. For Google Chrome you mentioned it’s “chrome.exe”, for Snipping Tool it’s “snippingtool.exe” etc.
Then it’s easy, you just need to write name of the program and call os.system. Don’t forget the start word there.
app_name = "chrome.exe"
os.system(f"start {app_name}")
I’m not sure which operating system you are on but for Mac OS this code will work for any application wether the name has a space or not.
app_name = text.strip("start ")
app = app_name
os.system("open -a ""+app+""")
Putting the name in quotations allows the use of spaces in the text and the -a
just tells it that you are trying to open an application rather than a file. Hope this helps.