I have a script which watches a folder and moves the files based on the activity of one of the folders. The problem comes when I run this script with idle the variable nameslist comes back as undefined when it runs. if I take out the idles and just loop it or run it once I do not get the error. I have tried setting the nameslist variable as a global and that was the same result.
What am I missing when it comes to idles and this variable. The other variable set to global works without a hitch. I am running this on a 10.10.4 machine.
global nameslist
global theWatchedFolder
set nameslist to " "
set theWatchedFolder to "Macintosh HD:Users:ifbell:Desktop:videofinished" as string
on idle
tell application "Finder"
set folderFiles to (every file in the folder theWatchedFolder whose name extension is "mp4")
if folderFiles is equal to {} then return
repeat with currentFile in folderFiles
set currentFileName to (the name of currentFile)
#display alert currentFileName
copy currentFileName to the end of items in nameslist
end repeat
end tell
#display alert listOfNames
tell application "Finder"
set AppleScript's text item delimiters to "."
repeat with n from 1 to count of nameslist
try
copy (item n of nameslist) to fileName
set {finname, nameExt} to {text 1 thru text item -2, text item -1} of fileName
display alert finname giving up after 10
set fileloc to "/Users/user/Desktop/videoTBP/" & finname & ".mov" as string
set finloc to "/Users/user/Desktop/videoprocessed/"
#display alert fileloc
do shell script "mv " & quoted form of fileloc & " " & quoted form of finloc & ""
on error errTxt number errNum
display notification finname & " has been moved"
end try
end repeat
end tell
end idle