This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by athrv chaulkar
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 open
open("brave") # Opens brave if installed
open("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 open
open("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 open
open("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 open
open("version") # Prints version of AppOpener
open("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 close
close("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 close
close("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 mklist
mklist()
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 mklist
mklist(filename="data.json")
#data.json file will be created in your working directory.
Creating TXT format file.
from AppOpener import mklist
mklist(filname="data.txt")
#data.txt file will be created in your working directory.
c. Using <path>
attribute
from AppOpener import mklist
mklist(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 mklist
mklist(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_appnames
apps = give_appnames()
print(apps) # Print appnames as (Dictionary)
b. Using <upper>
attribute
from AppOpener import give_appnames
apps = 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 🤗♥
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by athrv chaulkar
athrv chaulkar | Sciencx (2023-01-15T19:14:02+00:00) Opening applications without knowing their paths in python…. Retrieved from https://www.scien.cx/2023/01/15/opening-applications-without-knowing-their-paths-in-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.