I wrote a script as a folder action to take a saved file, check to see if it is a bank statement,move the file into a folder, and rename it. When I run it using choose file instead of as a folder action (in an effort to debug it) it works fine. When run as a folder action, it gets hung up, I think, on the line set name of new_item to newFileName. I cannot figure out why
Here is the script:
on adding folder items to folder_ after receiving new_item
–set new_item to choose file for debugging
set MonthNames to {“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”}
set MonthNumbers to {“01”, “02”, “03”, “04”, “05”, “06”, “07”, “08”, “09”, “10”, “11”, “12”}
set fileName to name of (info for new_item)
set fileExtension to name extension of (info for new_item)
ignoring case
if fileName contains “statement” then
repeat with i from 1 to 12
if fileName contains item i of MonthNames then
set thisMonth to item i of MonthNumbers
end if
end repeat
if thisMonth is “” then
tell me to quit
end if
set thisYear to do shell script “date +%Y”
display dialog “Enter Year For Statement” default answer thisYear
set thisYear to text returned of result
set newFileName to “APG Statement.” & thisYear & “.” & thisMonth & “.” & fileExtension
tell application “Finder”
set name of new_item to newFileName
move new_item to folder “Macintosh HD:Users:iMacHome:Documents:APG Statements:”
end tell
end if
end ignoring
end adding folder items to