#!/bin/bash

OUTPUT='/tmp/statusmail.txt'
START="$(date +%s)"
cname=`scutil --get ComputerName`
script=`basename $0`

# [[ $(date +%s -r mstall.zip) -lt $(date +%s --date="77 min ago") ]] && echo File is older than 1hr 17min

# [[ $(stat -f "%m" mstall.zip) -lt $(date -j -v-77M +%s) ]] && echo File is older than 1hr 17min
echo "" > ${OUTPUT}

ESUBJ="$KMINFO_MacroName"
export ESUBJ

# https://textkool.com/en/test-ascii-art-generator?text=idlecheck
# "ANSI Shadow" font
echo "// idlecheck" >> ${OUTPUT}
echo "  " `date` >> ${OUTPUT}
echo "   machine: ${cname}" >> ${OUTPUT}
echo "   script: ${script}" >> ${OUTPUT}
echo "  " `/usr/bin/sw_vers` >> ${OUTPUT}
echo "  " `sysctl kern.version` >> ${OUTPUT}
echo "  " `sysctl kern.ostype` >> ${OUTPUT}
echo "  " `sysctl kern.osrelease` >> ${OUTPUT}
echo "  " `sysctl kern.osrevision` >> ${OUTPUT}
echo "" >> ${OUTPUT}
echo "" >> ${OUTPUT}
echo "" >> ${OUTPUT}
echo "██╗██████╗ ██╗     ███████╗                 " >> ${OUTPUT}
echo "██║██╔══██╗██║     ██╔════╝                 " >> ${OUTPUT}
echo "██║██║  ██║██║     █████╗                   " >> ${OUTPUT}
echo "██║██║  ██║██║     ██╔══╝                   " >> ${OUTPUT}
echo "██║██████╔╝███████╗███████╗                 " >> ${OUTPUT}
echo "╚═╝╚═════╝ ╚══════╝╚══════╝                 " >> ${OUTPUT}
echo "                                            " >> ${OUTPUT}
echo "     ██████╗██╗  ██╗███████╗ ██████╗██╗  ██╗" >> ${OUTPUT}
echo "    ██╔════╝██║  ██║██╔════╝██╔════╝██║ ██╔╝" >> ${OUTPUT}
echo "    ██║     ███████║█████╗  ██║     █████╔╝ " >> ${OUTPUT}
echo "    ██║     ██╔══██║██╔══╝  ██║     ██╔═██╗ " >> ${OUTPUT}
echo "    ╚██████╗██║  ██║███████╗╚██████╗██║  ██╗" >> ${OUTPUT}
echo "     ╚═════╝╚═╝  ╚═╝╚══════╝ ╚═════╝╚═╝  ╚═╝" >> ${OUTPUT}
echo "" >> ${OUTPUT}
echo "--------------------------------------------" >> ${OUTPUT}


/bin/bash ${HOME}/Dropbox/bin/idlecheck_tasks >> ${OUTPUT}
/bin/bash ${HOME}/Dropbox/bin/idlecheck_quitvideowake >> ${OUTPUT}
/bin/bash ${HOME}/Dropbox/bin/idlecheck_quitaudioprevent >> ${OUTPUT}
/bin/bash ${HOME}/Dropbox/bin/idlecheck_caffeinatestuck >> ${OUTPUT}
/usr/bin/pmset displaysleepnow
/usr/bin/python3 ${HOME}/Dropbox/bin/send_status_mail3.py
DURATION=$[ $(date +%s) - ${START} ]
#cat /tmp/wakemaints.txt | fgrep "Wake reason"
rm ${OUTPUT}
sleep 10
