Pyttery
A downloadable tool for Windows, macOS, and Linux
YOU NEED PYTHON TO RUN THIS SCRIPT!
you need the following libraries
time
open the command prompt (CMD)
and write these lines of code
pip install numpy
pip install sounddevice
pip install psutil
pip install time
(time already exists by default but if it does not exist install)
This is Battery Saver script continuously monitors the battery status of the computer and uses audio feedback to alert the user when the battery is at a critical level or fully charged. Such functionality can be highly beneficial for several reasons:
- Immediate Awareness: It provides immediate feedback to the user through sound signals, eliminating the need for constant screen-checking to see the battery status.
- Energy Saving: It helps manage the device's battery life by alerting the user when it's necessary to charge the computer to prevent it from unexpectedly shutting down.
- Overheating Prevention: It reduces the risk of device overheating by advising the user when it's advisable to reduce computer usage to avoid excessive energy consumption.
- Efficient Usage: It promotes more efficient use of the computer by encouraging users to adhere to charging limits and make informed decisions about extended device usage.
In summary, this type of application provides an intuitive and non-invasive notification system to enhance user experience and optimize battery usage, thereby contributing to the device's longevity and performance in the long run.
To run your Python script in the background, you can use different approaches depending on your operating system:
Using nohup
on Unix/Linux/MacOS
nohup python your_script.py > output.log 2>&1 &
your_script.py
: Replace with the name of your Python script.> output.log 2>&1
: Redirects standard output and error output to a log file (output.log
).&
: Runs the process in the background.This command starts your Python script in the background. You can check the output and any errors in the output.log
file.
Using screen
or tmux
on Unix/Linux/MacOS
screen or tmux: screen
and tmux
are terminal multiplexers that allow you to run multiple terminal sessions, including running programs in the background.
screen -S session_name -dm python your_script.py
session_name
: Replace with a name for the screen session.your_script.py
: Replace with the name of your Python script.Detach from the screen session by pressing Ctrl+A
followed by d
To reattach to the session, use:
screen -r session_name
tmux:
tmux new-session -d -s session_name 'python your_script.py'
session_name
: Replace with a name for the tmux session.your_script.py
: Replace with the name of your Python script.Detach from the tmux session by pressing Ctrl+B
followed by d
. To reattach to the session, use:
tmux attach -t session_name
Using Windows Task Scheduler on Windows
Task Scheduler: On Windows, you can use Task Scheduler to schedule the execution of Python scripts in the background.
taskschd.msc
) and create a new task.C:\Python\python.exe
) and the path to your Python script.Additional Considerations
- Virtual Environment: If you're using a Python virtual environment, make sure to activate it before running the command to start your script.
- Monitoring Execution: Once started in the background, you can monitor the status of the process using commands like
ps
(on Unix/Linux/MacOS) or Task Manager (on Windows).
Here's how you can configure your Python script to run automatically at system startup on different operating systems:
Windows:
Find the Startup Folder:
C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Create a Shortcut:
- Right-click within the startup folder and select
New
->Shortcut
. - In the shortcut creation window, enter the full path to your Python interpreter followed by the path to your Python script. For example
C:\Path\To\Python\python.exe C:\Path\To\Pyttery\Script\pyttery.py
Make sure to replace C:\Path\To\Python\python.exe
with the actual path to your Python interpreter and C:\Path\To\Your\Script\your_script.py
with the actual path to your Python script.
Complete Shortcut Creation:
- Follow the prompts to complete creating the shortcut. You may need to provide administrator privileges to create the shortcut.
macOS:
Use System Preferences:
Edit the .plist
File (optional):
.plist
file for your script and add it to the LaunchAgents
folder..plist
file:<?xml version="1.0" encoding="UTF-8"?> <plist version="1.0"> <dict> <key>Label</key> <string>com.example.startup_script</string> <key>ProgramArguments</key> <array> <string>/usr/bin/python3</string> <string>/Path/To/Your/Script/your_script.py</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
.plist
file in ~/Library/LaunchAgents
.
launchctl load ~/Library/LaunchAgents/com.example.startup_script.plist
Linux (Ubuntu/Debian):
Use ~/.config/autostart:
.desktop
file for your Python script in this folder..desktop
file:[Desktop Entry] Type=Application Exec=/usr/bin/python3 /Path/To/Your/Script/your_script.py Hidden=false NoDisplay=false X-GNOME-Autostart-enabled=true Name=Startup Script
Add Execution Permissions:
Ensure the .desktop
file has execution permissions:
chmod +x ~/.config/autostart/startup_script.desktop
General Considerations:
Python Interpreter Path: Make sure to use the correct path to the Python interpreter (python
, python3
, or the full path) in the script execution command.
Verification and Testing: After adding your script to the startup folder, restart the operating system to verify that the script runs correctly at startup.
Download
Install instructions
instructions how to edit file
you can put your minimum and maximum parameters (of defalult minimum is 25% and maximum is 80% these are the parameters to save the battery and lengthen the life)
you can just edit line 5 and line 6
line 5
b_min = 25 # min %
just change the number, that number represents the minimum warning value as soon as the battery drops BELOW that value so if it is 25 it sounds when it drops to 24
line 6
b_max = 80 # max %
just change the number, that number represents the maximum warning value as soon as the battery rises to that value