How to set off an Alarm on Macbook when the battery is full?

If you’re one of those people who keep their laptop on charging and get busy doing other stuff IRL then you’ll like this post.

In this post, I’ll be sharing a tip which will help you set off an alarm on your Macbook as soon as the battery is full.

The idea here is to add a command to the Crontab file. Crontab is basically a list of commands that you want to run on a regular schedule.

To add a command to Crontab, open the terminal, type the following command and press enter.

crontab -e

Press ‘i’ key on the keyboard to edit the file and enter this command in the file –

*/1 * * * * python /Users/USERNAME/

The number 1 in the command above represents an interval of 1 minute. So the python script located in that respective directory will be run every 1 minute.

Exit the edit mode by pressing the escape key. Save the file by pressing SHIFT+Z twice.

Now create a python file called with the following script. Also, make sure to keep it in the right directory which you mentioned before in the crontab.

 import subprocess
import webbrowser

battery_info = 'pmset -g batt'
battery_info_output = subprocess.check_output(battery_info, shell=True)

if "charged" in battery_info_output:"file:///Users/omkarbhagat/scripts/play.mp3")

And also make sure to change the last line to locate a music file on your computer.

That’s all. With this setup, the script will run every 1 minute and the music file will run once the battery is full. 🙂

How to set off an Alarm on Macbook when the battery is full?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s