Beautiful! Thanks @macramole
For my future self and anyone else that might find it useful, here's a script that creates AudioStellar maps for all leaf directories in a tree - for zsh with a mac-specific path to the audiostellar-data-analysis
binary:
#!/bin/zsh
command_to_execute() {
echo "Executing command for folder: $1"
/Applications/AudioStellar.app/Contents/Resources/audiostellar-data-analysis/audiostellar-data-analysis --audio-max-length 4 "$1"
}
# Replace the below path with the root directory you want to traverse
root_dir="/Volumes/T7/evorenders"
# Function to check if a folder is a leaf folder (has no subdirectories)
is_leaf_folder() {
local folder=$1
local subdirs=$(find "$folder" -mindepth 1 -type d -print -quit 2>/dev/null)
[ -z "$subdirs" ]
}
# Traverse the directory tree and execute command for each leaf folder
traverse_and_execute() {
local dir=$1
local cmd=$2
for folder in "$dir"/*; do
if [ -d "$folder" ]; then
traverse_and_execute "$folder" "$cmd"
fi
done
if is_leaf_folder "$dir"; then
$cmd "$dir"
fi
}
# Call the function to traverse and execute the command for each leaf folder
traverse_and_execute "$root_dir" command_to_execute