Open In App

Open Applications using Python

Last Updated : 16 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to CLI application using Python3. We are going to include the below applications in the menu:

  • GOOGLE CHROME
  • MS EDGE
  • MS WORD
  • TELEGRAMopeln
  • WHATSAPP
  • NOTEPAD++
  • and all the applications installed…

Module Needed

AppOpener: It is the python library which helps in opening/closing any application without knowing it’s absolute path. The module works by making use of App name and App Id, It can be installed using the below command:

pip install AppOpener

Below code snippet showcases the use of the above module:

1. Open applications

Here, we aim to open whatsapp, which is installed in our system.

Python3




from AppOpener import open
open("whatsapp") # Opens whatsapp
open("whatsapp, telegram") # Opens whatsapp & telegram


2. Close applications

Here, we aim to close whatspp, if it is running  in forefront or background.

Python3




from AppOpener import close
close("whatsapp") # Closes whatsapp
close("telegram, brave") # Closes telegram & brave


3. CLI (Command Line Interface) application (open & close applications)

Python3




from AppOpener import open, close
 
def main():
  print()
  print("1. Open <any_name> TO OPEN APPLICATIONS")
  print("2. Close <any_name> TO CLOSE APPLICATIONS")
  print()
  open("help")
  print("TRY 'OPEN <any_key>'")
  while True:
      inp = input("ENTER APPLICATION TO OPEN / CLOSE: ").lower()
      if "close " in inp:
          app_name = inp.replace("close ","").strip()
          close(app_name, match_closest=True, output=False) # App will be close be it matches little bit too (Without printing context (like CLOSING <app_name>))
      if "open " in inp:
          app_name = inp.replace("open ","")
          open(app_name, match_closest=True) # App will be open be it matches little bit too
 
if __name__ == '__main__':
  main()


AppOpener is path independent, that is it is not limited as we manually provide path of application. It covers each and every installed application in windows OS.

You can see full applications of AppOpener [here](https://appopener.readthedocs.io/en/latest/Applications/).

Output:

CLI application opening & closing applications using AppOpener

Making CLI using pyttsx3 (Voice controlled)

You can chat with it or type number of applications to be opened or simply, you can also type software name or its short form like

'Photoshop' -> 'PS'

pyttsx3: It is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline and is compatible with both Python 2 and 3. An application invokes the pyttsx3.init() factory function to get a reference to a pyttsx3. Engine instance. It is a very easy-to-use tool which converts the entered text into speech. It can be installed using the below command:

pip install pyttsx3

Below code snippet showcases the use of the above module:

Python3




# create object
engine = pyttsx3.init()
 
# assign voice
voices = engine.getProperty('voices')
 
# changing index changes voices but only 0 and 1 are working here
engine.setProperty('voice', voices[1].id)
 
# run tool
engine.runAndWait()
 
print("")


os: The OS module in python provides functions for interacting with the operating system. OS, comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality

Below is the program to create an Application Menu using Python 

Python3




# import required module
import pyttsx3
import os
 
# driver code
 
# create object and assign voice
engine = pyttsx3.init()
voices = engine.getProperty('voices')
 
# changing index changes voices but only
# 0 and 1 are working here
engine.setProperty('voice', voices[1].id)
engine.runAndWait()
print("")
print("")
 
# introduction
print(" =============================================== Hello World!! ================================================")
engine.say('Hello World!!')
 
print("")
print(" My name is Divy Shah,I make this tool With this help of tool you can open below things.......")
 
print("\n\t 1.MICROSOFT WORD \t 2.MICROSOFT POWERPOINT \n\t 3.MICROSOFT EXCEL \t 4.GOOGLE CHROME \n\t 5.VLC PLAYER     \t 6.ADOBE ILLUSTRATOR \n\t 7.ADOBE PHOTOSHOP \t 8.MICROSOFT EDGE \n\t 9.NOTEPAD     \t 10.TELEGRAM \n\n\t\t     0. FOR EXIT")
 
print("\n     (YOU CAN USE NUMBER OR YOU CAN DO CHAT LIKE 'OPEN NOTEBOOK' etc....)")
 
print("\n ============================================ Welcome To My Tools ============================================")
pyttsx3.speak("Welcome to my tools")
print("")
print("")
 
pyttsx3.speak("chat with me with your requirements")
 
while True:
    # take input
    print(" CHAT WITH ME WITH YOUR REQUIREMENTS : ", end='')
    p = input()
    p = p.upper()
    print(p)
 
    if ("DONT" in p) or ("DON'T" in p) or ("NOT" in p):
        pyttsx3.speak("Type Again")
        print(".")
        print(".")
        continue
 
    # assignments for different applications in the menu
    elif ("GOOGLE" in p) or ("SEARCH" in p) or ("WEB BROWSER" in p) or ("CHROME" in p) or ("BROWSER" in p) or ("4" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("GOOGLE CHROME")
        print(".")
        print(".")
        os.system("chrome")
 
    elif ("IE" in p) or ("MSEDGE" in p) or ("EDGE" in p) or ("8" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("MICROSOFT EDGE")
        print(".")
        print(".")
        os.system("msedge")
 
    elif ("NOTE" in p) or ("NOTES" in p) or ("NOTEPAD" in p) or ("EDITOR" in p) or ("9" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("NOTEPAD")
        print(".")
        print(".")
        os.system("Notepad")
 
    elif ("VLCPLAYER" in p) or ("PLAYER" in p) or ("VIDEO PLAYER" in p) or ("5" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("VLC PLAYER")
        print(".")
        print(".")
        os.system("VLC")
 
    elif ("ILLUSTRATOR" in p) or ("AI" in p) or ("6" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("ADOBE ILLUSTRATOR")
        print(".")
        print(".")
        os.system("illustrator")
 
    elif ("PHOTOSHOP" in p) or ("PS" in p) or ("PHOTOSHOP CC" in p) or ("7" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("ADOBE PHOTOSHOP")
        print(".")
        print(".")
        os.system("photoshop")
 
    elif ("TELEGRAM" in p) or ("TG" in p) or ("10" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("TELEGRAM")
        print(".")
        print(".")
        os.system("telegram")
 
    elif ("EXCEL" in p) or ("MSEXCEL" in p) or ("SHEET" in p) or ("WINEXCEL" in p) or ("3" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("MICROSOFT EXCEL")
        print(".")
        print(".")
        os.system("excel")
 
    elif ("SLIDE" in p) or ("MSPOWERPOINT" in p) or ("PPT" in p) or ("POWERPNT" in p) or ("2" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("MICROSOFT POWERPOINT")
        print(".")
        print(".")
        os.system("powerpnt")
 
    elif ("WORD" in p) or ("MSWORD" in p) or ("1" in p):
        pyttsx3.speak("Opening")
        pyttsx3.speak("MICROSOFT WORD")
        print(".")
        print(".")
        os.system("winword")
 
    # close the program
    elif ("EXIT" in p) or ("QUIT" in p) or ("CLOSE" in p) or ("0" in p):
        pyttsx3.speak("Exiting")
        break
 
    # for invalid input
    else:
        pyttsx3.speak(p)
        print("Is Invalid,Please Try Again")
        pyttsx3.speak("is Invalid,Please try again")
        print(".")
        print(".")


Output:



Similar Reads

Open computer drives like C, D or E using Python
Have you ever wondered that you can open your drives by just typing C, D or E and then that drives are open.This can be possible by using Python. So, for performing this task this we are using os.startfile() method of OS library. This Method start a file with its associated program. Syntax: os.startfile(file_name) Return: None. Now let's see the co
1 min read
How to make HTML files open in Chrome using Python?
Prerequisites: Webbrowser HTML files contain Hypertext Markup Language (HTML), which is used to design and format the structure of a webpage. It is stored in a text format and contains tags that define the layout and content of the webpage. HTML files are widely used online and displayed in web browsers. To preview HTML files, we make the use of br
2 min read
How to open a file using the with statement
The with keyword in Python is used as a context manager. As in any programming language, the usage of resources like file operations or database connections is very common. But these resources are limited in supply. Therefore, the main problem lies in making sure to release these resources after usage. If they are not released, then it will lead to
4 min read
How to open External Programs using Tkinter?
Prerequisite: Tkinter, os Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications. In this article, w
2 min read
Python PIL | Image.open() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images. PIL.Image.open() Opens
2 min read
Python | sympy.sets.open() method
With the help of sympy.sets.open() method, we can make a set of values by setting interval values like right open or left open that means a set has right open bracket and left open brackets by using sympy.sets.open() method. Syntax : sympy.sets.open(val1, val2) Return : Return set of values with right and left open set. Example #1 : In this example
1 min read
Open a new Window with a button in Python-Tkinter
Python provides a variety of GUI (Graphic User Interface) such as PyQt, Tkinter, Kivy and soon. Among them, tkinter is the most commonly used GUI module in Python since it is simple and easy to learn and implement as well. The word Tkinter comes from the tk interface. The tkinter module is available in Python standard library.Note: For more informa
3 min read
How to open and close a file in Python
There might arise a situation where one needs to interact with external files with Python. Python provides inbuilt functions for creating, writing, and reading files. In this article, we will be discussing how to open an external file and close the same using Python. Opening a file in Python There are two types of files that can be handled in Pytho
4 min read
Python - Convert Tick-by-Tick data into OHLC (Open-High-Low-Close) Data
In this post, we'll explore a Python pandas package feature. We frequently find queries about converting tick-by-tick data to OHLC (Open, High, Low and Close). Using pandas kit this can be done with minimum effort. The OHLC data is used over a unit of time (1 day, 1 hour etc.) to perform a technical analysis of price movement. The First Step: The f
2 min read
How to open two files together in Python?
Prerequisites: Reading and Writing text files in Python Python provides the ability to open as well as work with multiple files at the same time. Different files can be opened in different modes, to simulate simultaneous writing or reading from these files. An arbitrary number of files can be opened with the open() method supported in Python 2.7 ve
2 min read