#!/usr/bin/env bash set -euo pipefail mode="list" playlist="" while [[ $# -gt 0 ]]; do case "$1" in --list) mode="list" shift ;; --playlist) mode="tracks" playlist="${2:?нужно имя плейлиста}" shift 2 ;; -h|--help) echo "Использование: music_playlists.sh [--list] [--playlist NAME]" exit 0 ;; *) echo "Неизвестный аргумент: $1" >&2 exit 2 ;; esac done if ! command -v osascript >/dev/null 2>&1; then echo "osascript не найден." >&2 exit 1 fi if [[ "$mode" == "list" ]]; then osascript <<'APPLESCRIPT' tell application "Music" set output to "" repeat with p in playlists set output to output & (name of p) & tab & (count of tracks of p) & linefeed end repeat return output end tell APPLESCRIPT exit 0 fi osascript - "$playlist" <<'APPLESCRIPT' on run argv set targetName to item 1 of argv tell application "Music" set output to "" repeat with p in playlists if name of p is targetName then repeat with t in tracks of p set output to output & (name of t) & tab & (artist of t) & tab & (album of t) & tab & (duration of t) & linefeed end repeat end if end repeat return output end tell end run APPLESCRIPT