Skip to content

Instantly share code, notes, and snippets.

@hyoban
Created June 9, 2023 06:48
Show Gist options
  • Save hyoban/1f6ab00696ce810160fbbca3d9b2226a to your computer and use it in GitHub Desktop.
Save hyoban/1f6ab00696ce810160fbbca3d9b2226a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Battery Notification
# @raycast.mode inline
# @raycast.refreshTime 30s
# Optional parameters:
# @raycast.icon 🔋
# Documentation:
# @raycast.author hyoban
# @raycast.authorURL https://raycast.com/hyoban
battery_percentage=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)
dis_charging=$(pmset -g batt | grep -Eo "discharging")
if [ $battery_percentage -lt 30 ] && [ $dis_charging ]; then
osascript -e 'display notification "电量还剩 '$battery_percentage'%" with title "快来充电啊"'
fi
if [ $battery_percentage -gt 80 ] && [ ! $dis_charging ]; then
osascript -e 'display notification "电量还剩 '$battery_percentage'%" with title "电量充足, 可以拔掉电源了"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment