May 19, 2024

My audio interface I use in the studio is capable of recording at 96khz. Now does recording in that higher rate make things sound good? Yes, it does. But one of the things that is a pain in the ass is converting things to get ready to record in Logic at 96Khz. I have a Logic template set up that defaults to being at 96khz, but if I drag say a Band in a Box generated background over, or want to use something I did that is in my iTunes, Logic will switch it to a lower rate. Ugh. So, I came up with this Applescript that I hacked together from various sites on the web, such as this one. It’s drag and drop, and will work with multiple files. Enjoy


property destlocation : missing value
property my_Folder : missing value
property s_a_folder : missing value
property command_start : "afconvert -f \"WAVEf\"" & space
property command_text_spec : space & "-d \"I24@96000\"" & space
property command_rate_spec : ""
property theitemname : missing value
property rootloc : missing value
property the_file : missing value
property the_data : missing value

on open these_items
my convert_audio(these_items)
end open

on convert_audio(these_items)

set command_rate_spec to ""
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set gen_item to this_item
set gen_info to info for gen_item
set gen_kind to folder of gen_info as Unicode text
if gen_kind is "true" then
tell me to set s_a_folder to true
else
set s_a_folder to false
end if
set rootloc to extract_parent_from(gen_item, s_a_folder)
if (rootloc as Unicode text) ends with ":" then
set rootloc to (rootloc as Unicode text)
else
set rootloc to ((rootloc & ":") as Unicode text)
end if
set destlocation to ((rootloc & "Converted_audio:") as Unicode text)
try
do shell script "mkdir" & space & (quoted form of (POSIX path of destlocation))
end try
if s_a_folder then
process_folder(this_item)
else
if (alias of gen_info is false) then
process_item(this_item)
end if
end if
end repeat
end convert_audio

on process_folder(this_folder)
set these_items to paragraphs of (do shell script "ls" & space & (quoted form of (POSIX path of this_folder)))
set this_folder to this_folder as Unicode text
repeat with i from 1 to the count of these_items
set this_item to (this_folder & (item i of these_items))
try
set the item_info to (info for (this_item as alias))
if folder of the item_info is true then
set this_item to this_item & ":"
process_folder(this_item)
else if (alias of the item_info is false) then
process_item(this_item as alias)
end if
on error the error_message number the error_number
if the error_number is in {-43, -2706, -2753, -48} then
else
display dialog the (error_number as string) & space & the error_message
end if
end try
end repeat
end process_folder

on process_item(this_item)
set my_Folder to (extract_parent_from(this_item, false) as Unicode text)
set sourcepath to (quoted form of (POSIX path of (this_item as Unicode text)))
set itemstring to replace_chars((my_Folder as Unicode text), rootloc, destlocation)
log rootloc
log destlocation
log itemstring
tell application "Finder"
set namepart to name extension of file this_item
set namefull to name of file this_item
end tell

set newname to replace_chars(namefull, namepart, "wav")
set destpath to (POSIX path of itemstring)
try
do shell script "mkdir -p" & space & (quoted form of destpath)
on error e1
display dialog e1 & namefull
end try
set the_out_file to (quoted form of (destpath & newname))
set full_command to command_start & sourcepath & command_text_spec & command_rate_spec & space & the_out_file

try
--log full_command
do shell script full_command
on error e3
display dialog "Error: " & the error_number & ". " & the error_message & return & namefull giving up after 5
end try
end process_item

on extract_parent_from(this_filepath, s_a_folder)
set alias_target to this_filepath as alias
tell application "Finder"
set _parent to container of alias_target
end tell
set parent_folder_path to _parent as string
return the parent_folder_path
end extract_parent_from

on replace_chars(this_text, bahad, goohood)
set AppleScript's text item delimiters to the bahad
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the goohood as Unicode text
set this_text to the item_list as Unicode text
set AppleScript's text item delimiters to ""
return this_text
end replace_chars

Leave a Reply