I wrote a script which opens a folder of audio files, opens each one in Quicktime, gets the running time of each, and then copies all of that information to the clipboard. After reading Matt Neuberg's excellent book, I found that I could do the same thing with System Events, without having to open each file in QT. The following scripts works great in most cases, but fails in a few. By the way, I limit the number of items processed to max_number for internal reasons.
- Certain mp3 files fail to be detected even though they have the correct type and creator codes and full read/write access. I can't figure out why.
- If I add the protected mpeg-4 type "M4P " to the extension list, those types are still not detected. Anyone know why?
- Why is it that one can say "set f to audio file f", but cannot say, for example "set f to every audio file of this folder"?
property extension_list : {"AIFF", "MPG3", "WAVE", "Mp3 "} property max_number : 30 tell application "Finder" set mylist to "" set this_folder to choose folder with prompt ¬ "Choose a folder to list:" set folder_items to every file of this_folder whose ¬ (file type is in extension_list) set found_items to count of folder_items if found_items > 0 then --- don't bother if list is empty if found_items > max_number then set folder_items to items 1 through 30 of folder_items set found_items to 30 --- no need to recount, we know it's 30 end if repeat with mycount from 1 to found_items set f to item mycount of folder_items as string tell application "System Events" try set f to audio file f on error error "Not an audio file." end try tell (get contents of f) set n to name of f set t to (its duration) / (its time scale) set hr to text 2 thru 3 of ((100 + t div hours) as string) set min to text 2 thru 3 of ((100 + t mod hours div minutes) as string) set sec to text 2 thru 3 of ((100 + t mod minutes div 1) as string) set frm to text 2 thru 3 of ((100 + t mod 1 * 30) as string) set d to "" if (hr is not equal to "00") then set d to hr & ":" end if --- use this one if you want frames displayed after a decimal point: --- set d to d & min & ":" & sec & "." & frm --- use this one if you want no frames displayed: set d to d & min & ":" & sec end tell end tell set mylist to mylist & mycount & tab & n & tab & d & tab & return end repeat set the clipboard to «class ktxt» of ((the mylist as text) ¬ as record) else set the clipboard to "" end if end tell
|