Converting a Folder of Audio Files to Different Format

Try this. You should be able to run it from Script Editor, or export it to an app and use that, or put it in the scripts folder and access it from the menu bar.

use scripting additions

set theOpenFilesFolder to "/Users/Path1/wavFiles/"
set theSaveFilesFolder to "/Users/Path2/rx2Files/"

set toff to POSIX file theOpenFilesFolder
tell application "Finder"
	set salt to (every item of folder toff) as alias list
	set wavList to {}
	repeat with sel in salt -- generate list of path of every wav file
		if name extension of sel is "wav" then -- if extension is .wav then add to list
			set end of wavList to quoted form of POSIX path of contents of sel
		end if
	end repeat
end tell

set fissile to "/Applications/ReCycle/ReCycle.app"
launch application fissile
set ot to 1 -- first time through
repeat with wav in wavList
	do shell script "open -a " & fissile & space & wav
	delay 1.5 -- adjust according to your computer's speed
	
	tell application "System Events"
		delay 0.5
		key code 1 using {command down, shift down} -- Save current document as a ReCycle file. [S]
		delay 1
		
		if ot is less than 2 then -- only for first time through
			key code 5 using {shift down, command down} -- Go to… [command-shift-G]
			delay 1
			keystroke theSaveFilesFolder
			delay 2
			set ot to 3 -- from now on, will skip the 'go to' actions
			key code 36
		end if
		delay 1.5
		
		key code 36 -- Return
		key code 13 using command down -- Close current document [w]
		delay 1
	end tell
end repeat
tell application "System Events" to key code 12 using command down -- quit recycle [q]

A couple of notes:

  • It launches ReCycle at the beginning and leaves it open until all files have been processed. This shouldn’t be an issue but we’ll see.
  • It sets a variable ‘ot’ and after the first file is processed, changes its value. Thereafter, it checks the value and since it has changed, skips the the command-shift-G part. This way, you should only go through it once.

I should add that I don’t have this app. I’ve been testing with Fission, which similarly has no applescript support, but it lets me open and close audio files.

As to your last question, recycle probably doesn’t support that. Using it to open files is different and only depends on recycle’s ability to work with the file type. Presumably, the developer doesn’t feel it’s in their interest to add these kinds of features.

You could always test it though. Launch the Terminal. Right-click on the app and click ‘Show Package Contents’. It should open the application bundle. Click through the ‘Contents’ and ‘MacOS’ folders and then drag the file —which should be just the app name and have a black icon with the word ‘exec’ on it— onto an open terminal window. Type a space and then -h (short for help). Hit enter. It might launch the application. It might display some help text. If it does, then it should let you know what capabilities it has. Conceivably, there might be more than one file in the folder.

1 Like

Just gave it a go, and, it seems it is going through all the motions. However, none of the converted images were stored, and, I get the following window on every single file within the folder.

The app Recycle stayed opened!

I really like this addition, I thought of something similar (remembering my days in Fortran) with a loop IF statement.

I will keep debugging the script you provided, yet, this is certainly headed in the right track.

Again, thank you!

Ran the test, and, it only opens the App Recycle itself. No additional help.

One minor inconvenience that still bugs me is that I can not “uncheck” where it says Auto-Play in order to disable the sound preview (of full audio file) when I am selecting the file.

Found an issue in the script…

key code 1 using {command down, shift down} -- Save current document as a ReCycle file. [S]
		delay 1

should be…

key code 1 using command down -- Save current document as a ReCycle file. [S]
		delay 1

Will continue to debug.

It is working, yet, currently saving the files in the incorrect folder, keeps open folder as the save folder. I’ll fix this and report back.

It is now WORKING…yeah!

Here is the updated script, edited 1 line and added/changed 2 of lines.

use scripting additions

set theOpenFilesFolder to "/Users/Path1/wavFiles/"
set theSaveFilesFolder to "/Users/Path2/rx2Files/"
-- Added the following line
set rx2FilesPath to theSaveFilesFolder

set toff to POSIX file theOpenFilesFolder
tell application "Finder"
	set salt to (every item of folder toff) as alias list
	set wavList to {}
	repeat with sel in salt -- generate list of path of every wav file
		if name extension of sel is "wav" then -- if extension is .wav then add to list
			set end of wavList to quoted form of POSIX path of contents of sel
		end if
	end repeat
end tell

set fissile to "/Applications/ReCycle/ReCycle.app"
launch application fissile
set ot to 1 -- first time through
repeat with wav in wavList
	do shell script "open -a " & fissile & space & wav
	delay 1.5 -- adjust according to your computer's speed
	
	tell application "System Events"
		delay 0.5
		-- Changed the following line
		-- key code 1 using {shift down, command down} -- Save current document as a ReCycle file. [S]
		-- to...
		key code 1 using command down -- Save current document as a ReCycle file. [S]
		delay 1
		
		if ot is less than 2 then -- only for first time through
			key code 5 using {shift down, command down} -- Go to… [command-shift-G]
			delay 1
			-- Changed the following line
			-- keystroke theSaveFilesFolder
			-- to...
			keystroke rx2FilesPath
			delay 2
			set ot to 3 -- from now on, will skip the 'go to' actions
			key code 36
		end if
		delay 1.5
		
		key code 36 -- Return
		key code 13 using command down -- Close current document [w]
		delay 1
	end tell
end repeat
tell application "System Events" to key code 12 using command down -- quit recycle [q]

So, from a manual task (taking a long time), it went to 4 min & 12 secs, then to 2 min & 10 secs, with a final time tally (using the above script) to 1 min & 20 secs.

Thank you Mockman!

Good catch. That is an artefact from my tests using Fission, which uses command-shift-S to open the ‘save as’ dialogue. I forgot and neglected to fix it when I made the post here.

In regards to your later post… that’s a good savings. You could probably trim some of the delay times as well. I would be surprised if it could get pushed down under a minute that way.

I’m glad it worked out for you.

By the way, while I don’t recall a bit of it, I studied fortran (probably IV with watfor and watfive — although I don’t know if I’m writing that correctly) in high school.

1 Like

No worries! Again, thanks!

Will certainly test reducing most of the delays! I also believe it will be under the minute mark.

You got it correct! Great memory. I studied it back in the day (~around 1975).