Script to convert .wav to .mp3

Is there a way to have a script convert a .wav file to .mp3 automatically?
I would like to add this to my menu when I right click a file.
I’ve found this other thread, but because I’m not familiar with Applescript, I have no idea how to adapt that to my needs:
https://macscripter.net/viewtopic.php?id=43095

I need the script to convert the selected file and then the mp3 would be saved next to the original .wav file, so the script would have to be written in a way that doesn’t specify a file or output. It’s dependent on the selected file. Hope it makes sense :slight_smile:

Thanks

AppleScript: 2.11
Browser: Safari 605.1.15
Operating System: macOS 10.15

I tested Nigel’s script from the linked thread and it worked fine:

set oldFile to quoted form of "/Users/Robert/Desktop/Fields of Gold.mp3"
set newFile to quoted form of "/Users/Robert/Desktop/Fields of Gold.wav"
do shell script ("/usr/bin/afconvert " & oldFile & " -o " & newFile & " -f 'WAVE' -d 'ulaw' -c 1")

If you don’t want to specify the output file then this also worked:

set oldFile to quoted form of "/Users/Robert/Desktop/Fields of Gold.mp3"
do shell script ("/usr/bin/afconvert " & oldFile & " -f 'WAVE' -d 'ulaw' -c 1")

If you want to convert an mp3 to a wav file and then back to an mp3, I guess you could simply repeat the above do shell script with the desired parameters. I don’t quite understand what you want to do here, though.

As far as implementing this with the right-click menu, I answered this question in one of your other threads.