Skip to content

Instantly share code, notes, and snippets.

@meereeum
Last active January 21, 2021 21:31
Show Gist options
  • Save meereeum/d0cc6068f5954b7eb638dc0fc7e1c8d1 to your computer and use it in GitHub Desktop.
Save meereeum/d0cc6068f5954b7eb638dc0fc7e1c8d1 to your computer and use it in GitHub Desktop.
~ automagical meeting scheduler ~ ///// 1. edit schedule (DATETIME2ID), 2. source from bash profile, 3. no more rummaging around for meeting IDs! just: $ zoom
#!/bin/bash
zoom() {
declare -A DATETIME2ID=(
[mon 4pm]=555123455 # meeting A
[thurs 11:30am]=555474747 # meeting B
[thurs 7pm]=555444777 # meeting C
[4pm]=555432100 # daily meeting D (superseded by A)
)
if [[ "$@" ]]; then # if argument passed, use as ID for call
unset closest
callid="$@"
else # else, find nearest meeting
NOW=$( date +%s )
timedelta() { echo $(( $NOW - $( date -d "$@" +%s ) )) | tr -d '-'; } # absolute value (;
declare -A timedelta2datetime
# iterate over newline-separated datetimes, alphabetically sorted
# this is a total hack to make "everyday" meetings have lowest priority,
# since numbers come before letters (so will be clobbered)
local IFS=$'\n' # see https://askubuntu.com/a/344418
for dt in $( echo "${!DATETIME2ID[@]}" | sed 's/m /m\n/g' | sort ); do
timedelta2datetime[$( timedelta "$dt" )]="$dt"
done
min=$( echo "${!timedelta2datetime[@]}" | tr ' ' '\n' | sort -g | head -n1 )
closest=${timedelta2datetime[$min]} # closest matching meeting datetime
callid=${DATETIME2ID[$closest]} # & corresponding meeting ID
fi
callurl="https://zoom.us/wc/join/$callid"
echo "$closest ►► $callurl"
if [[ "$OSTYPE" =~ "linux" ]]; then
_chrome=$( echo $( which chromium ) $( which chrome ) | awk '{print $1}' )
CHROME() { $_chrome --app="$@" &> /dev/null & disown; }
elif [[ "$OSTYPE" =~ "darwin" ]]; then
_chrome="$( ls -d /Applications/*Chrom* | xargs | awk -F'/Applications/' '{print $2}' )"
CHROME() { open -a "$_chrome" --args --app="$@" && \
caffeinate -d -w $( ps aux | awk '/zoom/ {print $2; exit}' ); }
# ^ don't sleep display during mtg
else # if not linux or macos, outta luck...
unset _chrome
fi
if [[ $_chrome ]]; then
CHROME $callurl
else
echo "[[ chrom{e,ium} not found ]]"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment