voice-dictation/scripts/install_autostart_macos.sh
2026-10-19 14:30:58 +03:00

43 lines
1.6 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Устанавливает LaunchAgent для автозапуска Voice Dictation при логине.
#
# Использование:
# ./scripts/install_autostart_macos.sh # установить
# ./scripts/install_autostart_macos.sh uninstall # удалить
set -euo pipefail
LABEL="com.vickenty.voicedictation"
PLIST_DEST="$HOME/Library/LaunchAgents/${LABEL}.plist"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEMPLATE="${SCRIPT_DIR}/com.vickenty.voicedictation.plist.template"
APP_EXECUTABLE="${VOICE_DICTATION_APP_EXECUTABLE:-/Applications/Voice Dictation.app/Contents/MacOS/VoiceDictation}"
if [[ "${1:-}" == "uninstall" ]]; then
launchctl unload "${PLIST_DEST}" 2>/dev/null || true
rm -f "${PLIST_DEST}"
echo "Удалено: ${PLIST_DEST}"
exit 0
fi
if [[ ! -x "${APP_EXECUTABLE}" ]]; then
echo "[ОШИБКА] Не найдено установленное приложение: ${APP_EXECUTABLE}"
exit 1
fi
mkdir -p "$(dirname "${PLIST_DEST}")"
sed \
-e "s|{{APP_EXECUTABLE}}|${APP_EXECUTABLE}|g" \
-e "s|{{WORKING_DIR}}|${HOME}/.dictate|g" \
-e "s|{{HOME}}|${HOME}|g" \
"${TEMPLATE}" > "${PLIST_DEST}"
launchctl unload "${PLIST_DEST}" 2>/dev/null || true
launchctl load "${PLIST_DEST}"
echo "Установлено: ${PLIST_DEST}"
echo "Приложение: ${APP_EXECUTABLE}"
echo
echo "Управление:"
echo " launchctl unload ${PLIST_DEST} # остановить"
echo " launchctl load ${PLIST_DEST} # запустить"
echo " ./scripts/install_autostart_macos.sh uninstall"