#!/bin/bash
# Sox Stereo to Mono Converter.
# Concept and Testing by Glen MacArthur, coded by Google Gemini 3.

# 1. Define your log and your tool
LOG="$HOME/.avl-mxe-file-action.log"
: > "$LOG"  # Clear out log file
TOOL_CMD="sox" # Change this to ffmpeg, convert, etc.

echo "--- Sox Stereo to Mono Started: $(date) ---" > "$LOG"

for item in "$@"; do
    # 2. Logic to handle files or folders
    if [ -d "$item" ]; then
        for f in "$item"/*; do
            # 3. Only process if it matches your extension
            [[ "$f" == *.wav ]] && $TOOL_CMD "$f" "${f%.*}-mono.wav" remix 1,2 >> "$LOG" 2>&1
        done
    else
        $TOOL_CMD "$item" "${item%.*}-mono.wav" remix 1,2 >> "$LOG" 2>&1
    fi
done

# 4. Success feedback
notify-send "Sox Stereo to Mono" "Task Finished! ✅"

