I'd like to use Hazel (a rule-based file system automator) for macOS to automatically move mixtape audio files from one folder to another, if their duration is longer than 30 minutes.
Hazel doesn't provide a built-in method of checking for audio file length (that I know of), but it provides the ability to run rules if an AppleScript condition is passed, i.e. return true
.
Judging from the screenshot below, I think it works if length of theFile > 30*60 seconds: return true
(pseudo code).
I'm not however sure how to accomplish this via AppleScript. Any ideas how to do it, or where to start? A search online didn't provide many basic ideas, but it seems to be possible.
Note: Giving advice on AppleScripts is outside the scope of the Hazel support AFAIK, so I can't get any help from them.
do shell script
command that will settheResult
totrue
orfalse
if you can figure out how to pass ittheFileName
:set theResult to (do shell script "[[ $(afinfo -r '" & theFileName & "' | awk '/estimated duration:/{print int($3/60)}') -gt 30 ]] && echo 'true' || echo 'false'") as boolean
. You can then add this line after it,return theResult
and it will be equivalent toreturn true
orreturn false
accordingly. – user3439894 Jul 8 '17 at 20:57do shell script
command to run faster, then use the following:" – user3439894 Jul 9 '17 at 15:04