#!/usr/bin/env bash
# Finder selection

usage() {
    echo "usage: $(basename $0)" 1>&2
    [ "$1" = "-h" ] || [ "$1" = "--help" ]; exit
}

[ "$1" = "-h" ] || [ "$1" = "--help" ] && usage "$@"

[[ $# != 0 ]] && usage

out="$(osascript "${BASH_SOURCE[0]%/*}"/.finder-selection.applescript 2>&1)" || exit
[[ -n "$out" ]] && while IFS= read path; do
    [[ "$path" == */ ]] && echo "${path::${#path}-1}" || echo "$path"
done <<< "$out";:
