Question

I want to make an automator workflow to find certain audio files in a folder, but I want it to look at the duration of those files. I'm looking for quite short audio samples of under 2 seconds. It doesn't appear to have the ability to filter by duration. Is there any other way to accomplish this in Automator?

Alternatively I can easily make a Smart Folder that contains what I'm looking for, but then Automator cannot find the contents of said Smart Folder in order to further manipulate them. Is there any way to get the contents of a smart folder in Automator?

Was it helpful?

Solution

Lets assume you have some action that's passing off files to a Filter Finder Items action, set as Find files where: All of the following are true and Kind is music.

This ensures what's passed to the next action, a Run Shell Script action, set as Shell: /bin/bash and Pass input as arguments are music files.

Replace the default code in the Run Shell Script action, having the above settings, with the following code:

for f in "$@"; do
    d="$(afinfo -r "$f" | awk '/estimated duration:/{print int($3)}')"
    if [[ $d -lt 2 ]]; then
        echo "$f"
    fi
done

The results of the above code with be the fully qualified pathname of music files with less than a 2 second duration and is passed to the next action as a list.


To address your second comment to my original answer, use the following code in place of the code above:

for f in "$@"; do
    d="$(afinfo -r "$f" | awk '/estimated duration:/{print $3}')"
    if (( $(echo "1.5 > $d" | bc -l) )); then
        echo "$f"
    fi
done
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top