Been using this for years. It works on selected cue, but you could make it repeat on each cue in selected. You’ll need to adjust the user settings to suit.
set userFormat to item 1 of {"wav", "aif"} -- Change this to "item 2" to convert to aiff
set userBitDepth to 16
set userBitRate to 44100
-- Declarations
global dialogTitle
set dialogTitle to "Convert to " & userFormat
-- Prepare some variables
if userFormat is "wav" then
set acceptableTypes to {"com.microsoft.waveform-audio"}
set formatString to "WAVE -d LEI"
else if userFormat is "aif" then
set acceptableTypes to {"public.aifc-audio", "public.aiff-audio"}
set formatString to "AIFF -d BEI"
else
return -- Protection against erroneous user modification
end if
-- Convert the cue
tell front workspace
try -- This protects against no selection (can't get last item of (selected as list))
set selectedCue to last item of (selected as list)
if q type of selectedCue is "Audio" then
set currentFileTarget to file target of selectedCue as alias
tell application "System Events"
set currentType to type identifier of currentFileTarget
end tell
if currentType is not in acceptableTypes then
set currentStart to start time of selectedCue
set currentEnd to end time of selectedCue
tell application "System Events"
set theContainer to path of container of currentFileTarget
set theExtension to name extension of currentFileTarget
if theExtension is "" then
set theName to name of currentFileTarget
else
set theFullName to name of currentFileTarget
set theName to text 1 through (-1 - ((length of theExtension) + 1)) of theFullName
end if
set newFileTarget to theContainer & theName & "." & userFormat
set fileExists to exists file newFileTarget
end tell
if fileExists is true then
display dialog "The destination file for the conversion already exists. What now?" with title dialogTitle with icon 0 ¬
buttons {"Cancel", "Replace"} default button "Replace" cancel button "Cancel"
end if
display dialog "Preparing to convert…" with title dialogTitle with icon 1 ¬
buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel" giving up after 3 -- You have 3s to change your mind
do shell script "afconvert -f " & formatString & userBitDepth & "@" & userBitRate & " " & ¬
quoted form of POSIX path of currentFileTarget & " " & quoted form of POSIX path of newFileTarget
set file target of selectedCue to newFileTarget
set start time of selectedCue to currentStart
set end time of selectedCue to currentEnd
set q name of selectedCue to "" -- Remove this line if you don't want to reset the cue name too
display dialog "Done." with title dialogTitle with icon 1 buttons {"OK"} default button "OK" giving up after 5
end if
end if
end try
end tell