Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 15, 2023 07:14 pm GMT

Opening applications without knowing their paths in python...

Hello there, I recently developed a Python module named AppOpener which allows opening Windows applications without knowing their absolute paths. It is useful for automation projects such as chatbots and AI.

What is AppOpener?

AppOpener is the python library to open/close any application without knowing it's absoulute path. The module works by making use of App Name and App Id.

What is App Name and App Id?

1. App Name

An appname, also known as an application name or original name, refers to the title given to a software program at its initial release. Examples of appnames include Firefox, Safari, and Google Chrome. These titles serve as a means of identification and branding for the respective applications.

2. App Id

An AppId is a unique identifier assigned by the Windows OS to each installed application. It serves as a means of identification and tracking, enabling the OS to perform various tasks such as allocating resources and ensuring compatibility. AppIds are essential for the efficient management and organization of applications on a system.

How do I get appnames and appids?

You can access the appnames and appids of all installed applications on Windows by using the PowerShell command Get-StartApps.

Screenshot of command

How the module works?

AppOpener utilizes the PowerShell command Get-StartApps to retrieve the appnames and appids of installed applications on the system. The output of this command is stored in a JSON file, with appname as the key and appid as the value.
When utilizing the functions of AppOpener, such as OPEN, the module searches through the stored JSON file and uses the PowerShell command explorer shell:appsFolder\\+appname to open the specified application.
This process allows for efficient and streamlined access to installed applications without the need for their absolute paths.

Using AppOpener


1. Install module

pip install AppOpener

2. Use AppOpener

from AppOpener import openopen("brave") # Opens brave if installedopen("brave, google chrome") # Opens barve and google chrome

Functions of AppOpener:


1. OPEN: Opens any application mentioned

Attributes

AttributeDescription
<match_closest>Open application which matches closest to string.
<output>Do not print any output text.

Examples:

a. Using <match_closest> attribute.

from AppOpener import openopen("barve, telgrm", match_closest=True)# Here, module detects the closest match of provided string (i.e barve is brave and telgrm is telegram)

b. Using <output> attribute

from AppOpener import openopen("brave", output=False)# No printing context (like 'OPENING BRAVE')

Commands

CommandDescription
?See this beatiful Documentation.
VERSIONPrint AppOpener version.
LSPrint list of applications.
HELPPrint supported commands.
FIND XYZFind application / applications.
RENAME -MUpdate petnames manually.
OLDNAME > NEWNAMEUpdate petname via command line.
UPDATELoad new appnames and appids.
DEFAULTRestore sefault appnames.
LOGPrint changes in petnames.

Commands can be accessed through OPEN function

Example:

from AppOpener import openopen("version") # Prints version of AppOpeneropen("ls") # Lists installed applications

2. CLOSE: Closes any application mentioned.

Attributes

AttributeDescription
<match_closest>Close application which matches closest to string.
<output>Do not print any output text.

Examples:

a. Using <match_closest> attribute

from AppOpener import closeclose("barve, telgrm", match_closest=True)# Here, module detects the closest match of provided string (i.e barve is brave and telgrm is telegram)

b. Using <output> attribute

from AppOpener import closeclose("brave", output=False)# No printing context (like 'CLOSING BRAVE')

3. MKLIST: Make a list of installed application with their appnames and appids.

Attributes

AttributeDescription
<filename>Filename of file to be created.
<path>Path of folder where file is to be created.
<output>Do not print any output text.

Examples:

a. General

from AppOpener import mklistmklist()

Here no attribute is used so it creates JSON file 'app_data.json', in your orking directory by default.

b. Using <filename> attributes

Creating JSON format file.

from AppOpener import mklistmklist(filename="data.json")#data.json file will be created in your working directory.

Creating TXT format file.

from AppOpener import mklistmklist(filname="data.txt")#data.txt file will be created in your working directory.

c. Using <path> attribute

from AppOpener import mklistmklist(path=r"C:\Users\athar\Documents\projects\AppOpener")#app_data.json file will be created in the provided directory.

d. Using <output> attribute

from AppOpener import mklistmklist(name="app_names.json", output=False)#app_names.json file will be created, without printing any output text.

4. GIVE_APPNAMES: Fetch appnames as dictionary.

Attribute

AttributeDescription
<upper>Dictionary should be uppercase

a. General

from AppOpener import give_appnamesapps = give_appnames()print(apps) # Print appnames as (Dictionary)

b. Using <upper> attribute

from AppOpener import give_appnamesapps = give_appnames(upper=True)print(apps) # Print appnames in uppercase as (Dictionary)

Links

I hope that this blog post was informative and helpful to those who read it. I also want to thank the dev.to team for making this platform a great place for developers to connect and share. Thank you for reading my first blog post


Original Link: https://dev.to/athrvvvv/opening-applications-without-knowing-their-paths-in-python-2k4b

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To