An Interest In:
Web News this Week
- April 14, 2024
- April 13, 2024
- April 12, 2024
- April 11, 2024
- April 10, 2024
- April 9, 2024
- April 8, 2024
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
.
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
Attribute | Description |
---|---|
<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
Command | Description |
---|---|
? | See this beatiful Documentation. |
VERSION | Print AppOpener version. |
LS | Print list of applications. |
HELP | Print supported commands. |
FIND XYZ | Find application / applications. |
RENAME -M | Update petnames manually. |
OLDNAME > NEWNAME | Update petname via command line. |
UPDATE | Load new appnames and appids. |
DEFAULT | Restore sefault appnames. |
LOG | Print 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
Attribute | Description |
---|---|
<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
Attribute | Description |
---|---|
<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
Attribute | Description |
---|---|
<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
- PYPI page - https://pypi.org/project/appopener/
- Github - https://github.com/athrvvvv/AppOpener
- Official documentation - https://AppOpener.readthedocs.io/en/latest/
- Github releases - https://github.com/athrvvvv/AppOpener/releases/
- Project changelog - https://github.com/athrvvvv/AppOpener/blob/module/CHANGELOG.md/
- Issue tracker - https://github.com/athrvvvv/AppOpener/issues/
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
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To