#!/usr/bin/env bash set -euo pipefail title="Терминал" message="" subtitle="" sound="" command="" while [[ $# -gt 0 ]]; do case "$1" in --title) title="${2:?нужен текст}" shift 2 ;; --message) message="${2:?нужен текст}" shift 2 ;; --subtitle) subtitle="${2:?нужен текст}" shift 2 ;; --sound) sound="${2:?нужно имя звука}" shift 2 ;; --command) command="${2:?нужна команда}" shift 2 ;; -h|--help) echo "Использование: notify_command.sh [--title TEXT] [--message TEXT] [--subtitle TEXT] [--sound NAME] [--command CMD]" exit 0 ;; *) echo "Неизвестный аргумент: $1" >&2 exit 2 ;; esac done notify() { osascript - "$title" "$subtitle" "$message" "$sound" <<'APPLESCRIPT' on run argv set theTitle to item 1 of argv set theSubtitle to item 2 of argv set theMessage to item 3 of argv set theSound to item 4 of argv if theSound is "" then display notification theMessage with title theTitle subtitle theSubtitle else display notification theMessage with title theTitle subtitle theSubtitle sound name theSound end if end run APPLESCRIPT } if [[ -z "$command" ]]; then if [[ -z "$message" ]]; then message="Уведомление из терминала" fi notify echo "Уведомление отправлено." exit 0 fi start=$(date +%s) set +e bash -c "$command" status=$? set -e end=$(date +%s) duration=$((end - start)) if [[ "$status" -eq 0 ]]; then message="Команда завершена успешно за ${duration} с" else message="Команда завершилась с кодом $status за ${duration} с" fi notify echo "$message" exit "$status"