#!/usr/bin/env bash set -euo pipefail mode="status" apply=0 assume_yes=0 while [[ $# -gt 0 ]]; do case "$1" in status|dark|light|auto) mode="$1" shift ;; --apply) apply=1 shift ;; --yes) assume_yes=1 shift ;; -h|--help) echo "Использование: appearance_toggle.sh [status|dark|light|auto] [--apply] [--yes]" exit 0 ;; *) echo "Неизвестный режим: $1" >&2 exit 2 ;; esac done current="Light" if defaults read -g AppleInterfaceStyle >/dev/null 2>&1; then current=$(defaults read -g AppleInterfaceStyle) fi automatic=$(defaults read -g AppleInterfaceStyleSwitchesAutomatically 2>/dev/null || echo "0") echo "Текущая тема: $current" echo "Автоматическое переключение: $automatic" if [[ "$mode" == "status" ]]; then exit 0 fi if [[ "$apply" -eq 0 ]]; then echo "Это предпросмотр. Добавьте --apply, чтобы переключить тему на $mode." exit 0 fi if [[ "$assume_yes" -eq 0 ]]; then read -r -p "Переключить тему на $mode? [y/N]: " answer if [[ ! "$answer" =~ ^[YyДд]$ ]]; then echo "Отменено." exit 1 fi fi case "$mode" in dark) osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to true' defaults write -g AppleInterfaceStyleSwitchesAutomatically -bool false ;; light) osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to false' defaults write -g AppleInterfaceStyleSwitchesAutomatically -bool false ;; auto) defaults write -g AppleInterfaceStyleSwitchesAutomatically -bool true ;; esac echo "Тема переключена: $mode."