#!/usr/bin/env bash set -euo pipefail mode="list" name="" input="" output="" force=0 while [[ $# -gt 0 ]]; do case "$1" in --list) mode="list" shift ;; --folders) mode="folders" shift ;; --run) mode="run" name="${2:?нужно имя Shortcut}" shift 2 ;; --input) input="${2:?нужен путь}" shift 2 ;; --output) output="${2:?нужен путь}" shift 2 ;; --force) force=1 shift ;; -h|--help) echo "Использование: shortcuts_run.sh [--list|--folders|--run NAME] [--input FILE] [--output FILE] [--force]" exit 0 ;; *) echo "Неизвестный аргумент: $1" >&2 exit 2 ;; esac done if ! command -v shortcuts >/dev/null 2>&1; then echo "Команда shortcuts не найдена. Нужна macOS 12 или новее." >&2 exit 1 fi case "$mode" in list) shortcuts list ;; folders) shortcuts list --folders ;; run) args=("run") if [[ -n "$input" ]]; then if [[ "$input" == "~"* ]]; then input="$HOME/${input#\~}" fi if [[ ! -f "$input" ]]; then echo "Входной файл не найден: $input" >&2 exit 1 fi args+=("-i" "$input") fi if [[ -n "$output" ]]; then if [[ "$output" == "~"* ]]; then output="$HOME/${output#\~}" fi if [[ -e "$output" && "$force" -eq 0 ]]; then echo "Выходной файл уже существует: $output (добавьте --force)" >&2 exit 1 fi args+=("-o" "$output") fi shortcuts "${args[@]}" "$name" if [[ -n "$output" && -f "$output" ]]; then echo "Результат: $output" fi ;; esac