Skip to content

Instantly share code, notes, and snippets.

@kvpb
Last active September 13, 2022 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvpb/026e185b6dbb6955c76300aa15b6297d to your computer and use it in GitHub Desktop.
Save kvpb/026e185b6dbb6955c76300aa15b6297d to your computer and use it in GitHub Desktop.
macOS Command-Line Alarm
#!/usr/bin/env zsh
if ! command -v gdate &> /dev/null || ! command -v bc &> /dev/null || ! command -v tput &> /dev/null || ! command -v osascript &> /dev/null
then
printf "%s\n" "Error: Software Incompatibility.\nThis ZSH script depends on ZSH, GDate, BC, TPUT and OSAScript."
exit 1
fi
[ -n "${1}" ] && [ 0 -le ${1} -a ${1} -le 23 ] && h=${1} || h=0 #[ -n "${1}" -a 0 -le ${1} -a ${1} -le 24 ] obviously fails.
[ -n "${2}" ] && [ 0 -le ${2} -a ${2} -le 59 ] && m=${2} || m=0
[ -n "${3}" ] && [ 0 -le ${3} -a ${3} -le 59 ] && s=${3} || s=0
t_0=$(gdate +%s.%N)
t_1=$(gdate -d "$(gdate +%D) ${h}:${m}:${s}.00000" +%s.%N)
t_t=$(printf "%s\n" "${t_1} - ${t_0}" | bc)
sleep ${t_t} #&
tput flash
tput flash > /dev/ttys002
osascript -e "set s to \"\" & (current date)" -e "display dialog s" > /dev/null 2>&1
unset t_t
unset t_1
unset t_0
unset s
unset m
unset h
# alarm.sh
# macOS Command-Line Alarm
#
# Karl V. P. B. `kvpb` AKA Karl Thomas George West `ktgw`
# +1 (DDD) DDD-DDDD
# +33 A BB BB BB BB
# local-part@domain
# local-part@domain
# https://www.linkedin.com/in//
# https://twitter.com/ktgwkvpb
# https://github.com/kvpb
# https://vm.tiktok.com/ZSwAmcFh/
#
# '... Mais quel genie. Il a allume un citron via un ordinateur ! Mais quel genie !'
# Copyright 2022 Karl Vincent Pierre Bertin
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment