With multiple selections allowed, if i chose “3” options in the list- the value of the variable im trying to loop, instead of it returning the values of the 3 items I need, its just returning the number 3… then the shell script is looking for files containing the number 3 instead of the value of the variable.
Im very new to coding, Ive tried so many thing, have been stuck on this for nearly a week and a need to reach out for help.
Hopefully someone here might be able to offer some advice.
Thank you in advance.
Doug
Open this Scriplet in your Editor:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property twelfth_root_2 : (2 ^ (1 / 12))
display dialog "Choose fundemental frequency in Hertz" default answer ""
set fRoot to text returned of result
set presets to {"b9", "9th", "m3", "3rd", "4th", "Dim5", "5th", "Aug5", "6th", "7th", "m7", "Oct"}
set theMode to (choose from list presets with prompt "Choose a character:" with multiple selections allowed)
if (theMode is false) then return -- user cancelled
set frequencies to {}
repeat with semitones from 1 to (count presets)
if (theMode contains {item semitones of presets}) then
set frequency to (round (fRoot * (twelfth_root_2 ^ semitones)))
set end of frequencies to ¬
{ ((round ((frequency / 2) / 5)) * 5), ((round (frequency / 5)) * 5), ((round ((frequency * 2) / 5)) * 5), ((round ((frequency * 4) / 5)) * 5), ((round ((frequency * 8) / 5)) * 5), ((round ((frequency * 16) / 5)) * 5), ((round ((frequency * 32) / 5)) * 5)}
end if
end repeat
set TheSearchPath to quoted form of "/Users/dh/Music/Samples/EXS24/ESX242/autocrop/Data"
set TheDestPath to quoted form of "/Users/dh/Music/Samples/EXS24/ESX242/autocrop/Term"
set aValue to ((current application's class "NSArray"'s arrayWithArray:(frequencies))'s valueForKeyPath:("@unionOfArrays.self")) as list
repeat with aValue from 1 to (count of frequencies) as text
set theSearch to aValue
set theResult to paragraphs of (do shell script "mdfind -onlyin " & TheSearchPath & ¬
" 'kMDItemFSName == \"*" & theSearch & "." & "0" & "Hz" & "*\"'") ¬
end repeat
repeat with i from 1 to count of theResult
if (count of theResult) is 1 and item 1 of theResult is "" then exit repeat
set the PosixFile to item i of theResult
try
do shell script "cp -f " & quoted form of PosixFile & space & TheDestPath
end try
end repeat