use ntfy server running on Debian to notify my iPhone when my MacBook battery is fully…
- User
use ntfy server running on Debian to notify my iPhone when my MacBook battery is fully charged
Assistant
To set up notifications for when your MacBook battery is fully charged using an ntfy server running on Debian, follow these steps:
-
Create a shell script on your MacBook to monitor the battery status. The script should check if the battery is at 100% and plugged in using the
pmset -g battcommand. -
Use a flag file to ensure the notification is only sent once when the battery reaches 100%.
-
Use
curlto send a notification to your ntfy server when the battery is fully charged. The script should look like this:
#!/bin/bash FLAG_FILE="/tmp/battery_fully_charged.flag" NTFY_SERVER="http://my-ntfy-server:80" TOPIC="mymacbook_battery" MESSAGE="MacBook battery is fully charged!" battery_status=$(pmset -g batt) if [[ $battery_status == *"AC"* && $battery_status == *"100%; charged;"* ]]; then if [ ! -f "$FLAG_FILE" ]; then curl -X POST -d "$MESSAGE" "$NTFY_SERVER/$TOPIC" touch "$FLAG_FILE" fi else if [ -f "$FLAG_FILE" ]; then rm "$FLAG_FILE" fi fi-
Save the script to
/usr/local/bin/check_battery.shand make it executable withchmod +x /usr/local/bin/check_battery.sh. -
Set up a cron job to run the script every 5 minutes by adding the following line to your crontab (
crontab -e):
*/5 * * * * /usr/local/bin/check_battery.sh-
On your iPhone, install the ntfy app and subscribe to the topic
mymacbook_battery. -
Ensure your ntfy server is accessible from your MacBook and properly configured to send notifications to your iPhone.
This setup will notify your iPhone via the ntfy server whenever your MacBook battery is fully charged.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.