Skip to content

Instantly share code, notes, and snippets.

@lowk3v
Created June 10, 2024 03:07
Show Gist options
  • Save lowk3v/dc429ef86a7bb7eca7760381d0f210d9 to your computer and use it in GitHub Desktop.
Save lowk3v/dc429ef86a7bb7eca7760381d0f210d9 to your computer and use it in GitHub Desktop.

Revisions

  1. lowk3v created this gist Jun 10, 2024.
    48 changes: 48 additions & 0 deletions mac-words-reminder.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    #!env bash

    mac_notify() {
    # Usage: mac_notify "title" "subtitle" "message" "sound"
    sound="Glass"

    if [ "$#" -ge 4 ]; then
    # mac_notify "title" "subtitle" "message" "sound"
    title="with title \"$1\""
    subtitle="subtitle \"$2\""
    message="$3"
    sound="$4"
    elif [ "$#" -eq 3 ]; then
    # mac_notify "title" "subtitle" "message"
    title="with title \"$1\""
    subtitle="subtitle \"$2\""
    message="$3"
    elif [ "$#" -eq 2 ]; then
    # mac_notify "title" "message"
    title="with title \"$1\""
    subtitle=""
    message="$2"
    elif [ "$#" -eq 1 ]; then
    # mac_notify "message"
    title="with title \"$1\""
    subtitle=""
    message="-"
    else
    echo "Usage: mac_notify <title> <subtitle> <message> <sound>"
    return
    fi
    cmd="display notification \"$message\" $title $subtitle sound name \"$sound\""
    /usr/bin/osascript -e "$cmd"
    }

    function random_sentence() {
    # 0 8-23 * * * source $HOME/mac-words-reminder.sh && random_sentence words.txt
    vocabulary=${1:-"$HOME/vocabulary.txt"}
    sentence=$(/opt/homebrew/bin/shuf -n 1 $vocabulary)
    eng=$(echo $sentence | awk -F: '{print $1}')
    vn=$(echo $sentence | awk -F: '{print $2}')

    if [ -z "$vn" ]; then
    mac_notify "$eng" "."
    else
    mac_notify "$eng" "$vn"
    fi
    }