Ok, ok, I have finally taken the plunge to “try” learn AppleScript in my retirement years. And, this puts me in the NOOB category, thus, please be a little patient with me. I think I had a little success in my first venture, yet, I am seeking some feedback/guidance as it relates to the script’s effectiveness/efficiency.
Description of script tasks:
I was performing manual tasks of converting audio files from *.wav to *.rx2 file type to be able to use these in other applications requiring the REX2 format. I have been using PropellerHead’s Recycle 2 (very dated package) software to do so. I developed this script to enable the file selections (Folder B) and auto-convert & save to another folder (Folder C). Both these folders are located within Folder A.
The script currently does what it is intended for based on how ReCycle 2 was setup. However, I am not able to specifically point the ReCycle to a specific folder and/or file, thus, I need some inputs in this area.
The script currently goes to the Folder B (wav files location) and counts the number of files within the folder. Then uses such “count” to iterate through a Repeat loop to pick a file (using a pinter within the app’s file finder), almost like a pointer. So, it pick file 1 through X. Recycle then grabs the file, and proceeds to store it in Folder C (rx2 files location).
Here is the current script:
tell application "Finder"
set theFolder to (POSIX file "/Users/myname/Documents/MusicAppFolder/wavFiles_to_rx2Files/wavFiles/") as text
set audioFilesType to "wav" as text
set NumOfFiles to count of (files in folder theFolder whose name extension is audioFilesType)
set filesList to every file in folder theFolder whose name extension is audioFilesType
repeat with i from 1 to NumOfFiles
set openFile to item i of filesList as text
tell application "ReCycle" to activate
tell application "System Events"
key code 13 using command down -- Close current document. [W]
delay 1
key code 31 using command down -- Open an audio file or a ReCycle file. [O]
delay 1
-- key code 48 -- Position cursor for file selection. [TAB]
-- delay 1
repeat i times
key code 125 -- Select 1st file in Window using Arrrow Down
delay 1
end repeat
-- key stroke openFile -- Specifies audio file to select.
-- delay 1
key code 36 -- Return [Return]
delay 1
key code 1 using command down -- Save current document as a ReCycle file. [S]
delay 1
repeat 3 times -- ReCycle application requires 3 Tabs to get to Save selection
key code 48
delay 1
end repeat
key code 36 -- Return
key code 13 using command down -- Close current document.
delay 1
key code 12 using command down -- Quit ReCycle. [Q]
delay 1
end tell
end repeat
end tell
Challenges with script:
(1) I would prefer to have the ability to specify the Folder location and File name of the files being converted, instead of the current “pointer” using the Count. The Count’s problem is that if there are other files within that same directory, then, it could potentially grab the incorrect file and crash.
(2) In addition, I would like to specify the Folder location so I can use other folders as well. I tried using the List of Files array, yet, was not successful.
Anyway, it would be great if I could get some feedback on these challenges and/or the script I wrote. I am sure there are much better ways (or different ways) of doing such. Thank you!
p.s. Does one have the ability to use Finder during the execution of this script? Is Finder a “hostage” during such script routines?