A downloadable tool for Windows, macOS, and Linux

YOU NEED PYTHON TO RUN THIS SCRIPT!

you need the following libraries

numpy

sounddevice

psutil

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:

  1. Immediate Awareness: It provides immediate feedback to the user through sound signals, eliminating the need for constant screen-checking to see the battery status.
  2. 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.
  3. 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.
  4. 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 dTo 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.

  • Open Task Scheduler (taskschd.msc) and create a new task.
  • Specify the path to your Python interpreter (e.g., C:\Python\python.exe) and the path to your Python script.
  • Configure the task to run with appropriate privileges and without requiring interactive access.

  • 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:

  • Go to Apple Menu -> System Preferences -> Users & Groups.
  • Select your username and go to the "Login Items" tab.
  • Click the "+" button and add your Python script to the list. Be sure to specify the full path to the script.

  • Edit the .plist File (optional):

  • You can create a .plist file for your script and add it to the LaunchAgents folder.
  • Example content for a .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>

  • Save this .plist file in ~/Library/LaunchAgents.
  • Start your script with the command:
  • launchctl load ~/Library/LaunchAgents/com.example.startup_script.plist
    Linux (Ubuntu/Debian): 

    Use ~/.config/autostart:

  • Create a .desktop file for your Python script in this folder.
  • Example content for a .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.




  • StatusReleased
    CategoryTool
    PlatformsWindows, macOS, Linux
    AuthorRpx

    Download

    Download
    pyttery.py 1.9 kB

    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