#!/bin/bash
# Mock for ~/Applications/magick.
# identify: delegate to real system identify.
# convert (resize call): copy in-place and embed the comment so the file
#   looks processed on the next run.
if [ "$1" = "identify" ]; then
    shift
    identify "$@"
    exit $?
fi

# Parse -set comment <value> and the output file (last arg) from the argument list
COMMENT=""
OUTFILE="${@: -1}"
args=("$@")
for i in "${!args[@]}"; do
    if [ "${args[$i]}" = "-set" ] && [ "${args[$i+1]}" = "comment" ]; then
        COMMENT="${args[$i+2]}"
    fi
done

if [ -n "$COMMENT" ]; then
    convert "$OUTFILE" -set comment "$COMMENT" "$OUTFILE"
fi
