Tuesday, June 27, 2017

#1 2017-06-11 02:44:17 pm

Beeman
Member
Registered: 2006-03-07
Posts: 69

getting length of .M4A audio file

Hello,

I recorded an audio file via Quicktime. I would like to be able to use the length of the file in the hours:minutes:seconds format to display in dialog box.
Does anyone know how to get at that attribute in a file stored on my hard drive?

thanks in advance

Browser: Safari 602.3.12
Operating System: Mac OS X (10.10)

Offline

 

#2 2017-06-11 07:07:13 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 5023

Re: getting length of .M4A audio file

This uses Spotlight metadata to get the value in seconds, which is easily converted to hh:mm:ss format.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theFile to POSIX path of (choose file)
-- build predicate
set theFile to current application's NSString's stringWithString:theFile
set theName to theFile's lastPathComponent()
set theContainer to theFile's stringByDeletingLastPathComponent()
set thePred to current application's NSPredicate's predicateWithFormat_("kMDItemFSName == %@", theName)
-- build and start query
set theQuery to current application's NSMetadataQuery's new()
theQuery's setPredicate:thePred
theQuery's setSearchScopes:{theContainer}
theQuery's startQuery()
-- loop until it's stopped gathering
repeat while theQuery's isGathering() as boolean
   delay 0.1
end repeat
-- stop and get the first NSMetadataItem (there can only be one in this case)
theQuery's stopQuery()
set metaItem to theQuery's resultAtIndex:0
-- get the value you want
set theSeconds to (metaItem's valueForAttribute:(current application's NSMetadataItemDurationSecondsKey)) as real


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.099 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)