Pause Resource-Intensive Rule(s) on Low Laptop Battery

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

IMPORTANT NOTE: First and foremost, Hazel is not a resource-intensive application. It is written very efficiently and does not appreciably decrease battery life under normal use.

That said, certain Hazel rules may cause resource intensive applications or instructions to run which may decrease remaining battery time (e.g. image or video processing workflows, remote server backup, etc.).

This rule will allow you to pause other rules when you have less than a certain number of minutes remaining on your MacBook's battery.

Use Case: A rule is set up to re-encode downloaded video files. You're at a coffee shop without an outlet, and you only have 45 minutes of battery time left. Re-encoding starts, and your battery life decreases to 15-20 minutes because the CPU is running at 90-100%.

Solution: Wait until you're back home on outlet power to start the encoding process and enjoy a half hour more of internet browsing.


Step 1: Create a New Rule that is ABOVE your process intensive rule

Code: Select all
if (all) of the following are true for (the files or folders being matched)
   Passes shell script (embedded script)

Do the following for the matched file or folder:
   Ignore file


The embedded script is this:

Code: Select all
ISCHARGING=$(ioreg -rc "AppleSmartBattery" | grep -c "\"IsCharging\" = Yes")

#We should immediately return a non-match if the laptop is charging
if [ "$ISCHARGING" == "1" ];
then
exit 1;
fi

#Minutes total if the battery is discharging
MINUTESTOTAL=$(ioreg -rc "AppleSmartBattery" | grep "InstantTimeToEmpty" | awk -F " = " '{print $2}')

MINTES_REMAINING_SHOULD_PAUSE=45

if [ "$MINUTESTOTAL" -lt "$MINTES_REMAINING_SHOULD_PAUSE" ]
then
exit 0;
fi

#We are on battery, but the battery is relatively full
exit 1;



And we're done! That's it. Rules that come after this rule will not execute until you find an outlet and charge the MacBook up.

Step 2: Adjust MINUTES_REMAINING_SHOULD_PAUSE to whatever you want...

With the default script, rules will pause when there is less than 45 minutes remaining on the battery. If the number was changed to 60, subsequent rules will not execute unless more than one hour remains on the battery.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Nice one. While I am thinking of possibly adding a rule condition to check if battery is being this should do the trick until then. Thanks.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Tips & Tricks - DO NOT POST QUESTIONS