# 文件名前缀 if [ -z "$input" ]; then rand=$(LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 4) filename="${date_str}_${rand}" else filename="${date_str}_$input" fi
file_path="$target_dir/$filename.png"
# ---- 保存剪贴板图片 ---- tmp_file=$(mktemp /tmp/clip_XXXX.png) osascript -e 'try set theImage to the clipboard as «class PNGf» set thePath to POSIX file "'"$tmp_file"'" as text set theFile to open for access file thePath with write permission set eof of theFile to 0 write theImage to theFile close access theFile on error errMsg error errMsg end try'
if [ ! -f "$tmp_file" ]; then echo"Clipboard image save failed" exit 1 fi
mv"$tmp_file""$file_path"
# PNG 压缩(可选) ifcommand -v pngquant >/dev/null 2>&1; then pngquant --force --output "$file_path""$file_path" fi