Skip to content

Instantly share code, notes, and snippets.

@jeremy4971
Last active January 6, 2024 10:30
Show Gist options
  • Save jeremy4971/8f4b09b0bf64bc6936a78618f5e27166 to your computer and use it in GitHub Desktop.
Save jeremy4971/8f4b09b0bf64bc6936a78618f5e27166 to your computer and use it in GitHub Desktop.
#!/bin/bash
###
#
# Created : 2022-04-05
# Last Modified : 2022-10-16
# Version : 1.01
# Tested with : macOS 12.6
#
###
# Kill stucked IBM Notifier processes just in case
killall "IBM Notifier Alert"
killall "IBM Notifier Popup"
# Read uptime
days=$(uptime | awk '{ print $4 }' | sed 's/,//g')
num=$(uptime | awk '{ print $3 }')
# For testing purpose
#days="days"
#num="42"
# Mac@IBM Notifications binary path
NA_PATH="/Applications/IBM Notifier.app/Contents/MacOS/IBM Notifier"
#################
### FUNCTIONS ###
#################
prompt_alert() {
WINDOWTYPE="alert"
TITLE="Ordinateur allumé depuis $num jours."
BUTTON_1="Redémarrer maintenant"
BUTTON_2="Honteusement ignorer"
SUBTITLE="Votre Mac tourne au ralenti et des correctifs de sécurité ne peuvent pas être appliqués, compromettant ainsi la sécurité de vos données profesionnelles."
CMD_RESULT=$("${NA_PATH}" "-type" "${WINDOWTYPE}" "-title" "${TITLE}" "-subtitle" "${SUBTITLE}" "-main_button_label" "${BUTTON_1}" "-secondary_button_label" "${BUTTON_2}"; echo $?)
}
prompt_popup() {
WINDOWTYPE="systemalert"
BAR_TITLE="Notification YOURCOMPANY"
TITLE="Aucun redémarrage depuis plus de $num jours."
BUTTON_1="Redémarrer maintenant"
BUTTON_2="Honteusement ignorer"
SUBTITLE="Votre Mac tourne au ralenti et des correctifs de sécurité ne peuvent pas être appliqués, compromettant ainsi la sécurité de vos données profesionnelles."
CMD_RESULT=$("${NA_PATH}" "-type" "${WINDOWTYPE}" "-bar_title" "${BAR_TITLE}" "-title" "${TITLE}" "-subtitle" "${SUBTITLE}" "-main_button_label" "${BUTTON_1}" "-secondary_button_label" "${BUTTON_2}"; echo $?)
}
#####################
### END FUNCTIONS ###
#####################
# Notification logic
if [ "$days" = "days" ]; then
if [ "$num" -le 13 ]; then
echo "Uptime inférieur ou égal à 13 jours. Exit."
exit 0
elif [ "$num" -ge 14 ] && [ "$num" -le 21 ]; then
echo "Uptime entre 14 et 21. Alerte."
prompt_alert
elif [ "$num" -ge 22 ]; then
echo "Uptime supérieur à 22. Popup."
prompt_popup
fi
else
echo "Uptime 0 ou 1 jour. Exit"
exit 0
fi
# Result
if [[ "$CMD_RESULT" -eq 2 ]]; then
echo "2 : Cancel"
afplay "/System/Library/Sounds/Sosumi.aiff"
exit 0
elif [[ "$CMD_RESULT" -eq 0 ]]; then
echo "0 : Redémarrer"
osascript -e 'tell application "Finder"
restart
end tell'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment