When it comes to the mdfind command one of my variables, (“aValue”, holds between 12-200 values) is not looping through its list, its just counting the amount of items its storing and using that as 1 value for the calculation. Can anyone explain where Im going wrong?
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "Metadata Lib" version "2.0.0"
use mdLib : script "Metadata Lib" version "2.0"
property twelfth_root_2 : (2 ^ (1 / 12))
tell application "Finder"
delete (every item of folder "Mojave:Users:dh:Music:Samples:EXS24:ESX242:autocrop:Term:")
end tell
display dialog "Choose fundemental frequency in Hertz" default answer ""
if text returned of result contains "A" then
set fRoot to 440.0
else if text returned of result contains "B" then
set fRoot to 493.88
else if text returned of result = "Bb" then
set fRoot to 466.16
else if text returned of result contains "C" then
set fRoot to 523.25
else if text returned of result contains "Ab" then
set fRoot to 415.3
else if text returned of result contains "G" then
set fRoot to 392.0
else if text returned of result contains "Gb" then
set fRoot to 369.99
else if text returned of result contains "F" then
set fRoot to 349.23
else if text returned of result contains "E" then
set fRoot to 329.63
else if text returned of result contains "Eb" then
set fRoot to 311.13
else if text returned of result contains "D" then
set fRoot to 293.66
else if text returned of result contains "Db" then
set fRoot to 277.18
else
set fRoot to text returned of result
end if
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 / 256) / 5)) * 5), ((round ((frequency / 128) / 5)) * 5), ((round ((frequency / 64) / 5)) * 5), ((round ((frequency / 32) / 5)) * 5), ((round ((frequency / 16) / 5)) * 5), ((round ((frequency / 8) / 5)) * 5), ((round ((frequency / 4) / 5)) * 5), ((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), ((round ((frequency * 64) / 5)) * 5), ((round ((frequency * 128) / 5)) * 5), ((round ((frequency * 256) / 5)) * 5), ((round ((frequency * 512) / 5)) * 5)}
end if
end repeat
set TheSearchPath to quoted form of POSIX path of "/Users/dh/Music/Samples/EXS24/ESX242/autocrop/Data"
set TheDestPath to quoted form of POSIX path 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 --no matches
set the PosixFile to item i of theResult
try
do shell script "cp -f " & quoted form of PosixFile & space & TheDestPath
end try
end repeat
delay 5
-- Strip Suffix of CSV
set sFolder to "Mojave:Users:dh:Music:Samples:EXS24:ESX242:autocrop:Term:"
tell application "Finder"
set fLst to (every item in folder sFolder whose kind is not "Folder") as alias list
if fLst is {} then return
repeat with anItem in fLst
set name_ext to anItem's name
set ext to anItem's name extension
if (offset of "." in name_ext) > -18 is true then
set prefix to (characters 1 thru -18 of name_ext) as text
if not ext = "" then set ext to ""
set name of anItem to prefix & ext
end if
end repeat
return
end tell
set thePrefix to "Mojave:Users:dh:Music:Samples:EXS24:ESX242:autocrop:Term:" whose kind is not "Folder" as list
set wavSearchPath to quoted form of POSIX path of "/Users/dh/Music/Samples/EXS24/ESX242/autocrop/files"
set aliasDestPath to quoted form of POSIX path of "/Users/dh/Music/Samples/EXS24/ESX242/autocrop/alias"
repeat with thePrefix from 1 to (count of theResult) as text
set wavSearch to (thePrefix) -- "yourSearchstring" --place your sample-searchstring here to test the search
set theAlias to paragraphs of (do shell script "mdfind -onlyin " & wavSearchPath & " 'kMDItemFSName == ¬
\"*" & wavSearch & "*\"'") ¬
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
result
end repeat
-- tell application "Finder"
-- delete (every item of folder "Mojave:Users:dh:Music:Samples:EXS24:ESX242:autocrop:alias:")
-- end tell
-- end run