#!/usr/bin/env bash set -euo pipefail input="" list_only=0 target="" extra=() while [[ $# -gt 0 ]]; do case "$1" in --list) list_only=1 shift ;; --input) input="${2:?нужен путь}" shift 2 ;; --) shift extra=("$@") break ;; -h|--help) echo "Использование: run_automation.sh [--list] [--input FILE] PATH [-- ARGS...]" exit 0 ;; -*) echo "Неизвестный аргумент: $1" >&2 exit 2 ;; *) if [[ -z "$target" ]]; then target="$1" else extra+=("$1") fi shift ;; esac done if [[ "$list_only" -eq 1 ]]; then echo "Automator workflows:" find "$HOME/Library/Services" "$HOME/Library/Workflows" -maxdepth 3 -name '*.workflow' -print 2>/dev/null | sed -n '1,40p' || true echo echo "AppleScript files:" find "$HOME/Library/Scripts" -maxdepth 3 \( -name '*.scpt' -o -name '*.applescript' \) -print 2>/dev/null | sed -n '1,40p' || true exit 0 fi if [[ -z "$target" ]]; then echo "Укажите workflow или скрипт, либо используйте --list." >&2 exit 2 fi if [[ "$target" == "~"* ]]; then target="$HOME/${target#\~}" fi if [[ -n "$input" ]]; then if [[ "$input" == "~"* ]]; then input="$HOME/${input#\~}" fi if [[ ! -f "$input" ]]; then echo "Входной файл не найден: $input" >&2 exit 1 fi fi if [[ ! -e "$target" ]]; then echo "Объект не найден: $target" >&2 exit 1 fi if [[ -d "$target" && "$target" == *.workflow ]]; then if [[ -n "$input" ]]; then /usr/bin/automator -i "$input" "$target" else /usr/bin/automator "$target" fi elif [[ "$target" == *.applescript || "$target" == *.scpt || -f "$target" ]]; then args=("$target") if [[ -n "$input" ]]; then args+=("$input") fi if [[ ${#extra[@]} -gt 0 ]]; then args+=("${extra[@]}") fi /usr/bin/osascript "${args[@]}" else echo "Неизвестный тип объекта: $target" >&2 exit 2 fi