applescript remove spaces replace with underscore
I am running this Applescript in an applet and it works great other than the fact that it only changes HALF of the file names. Then if you run it again it does HALF of those then HALF again and so on. Anyone have any insight or a better way to accomplish the goal?
set defDel to AppleScript'stext item delimiters
tell application "Finder"
set theFolder to folder (choose folder)
repeat with thisItem in theFolder
set thename to name of thisItem
if thename contains " " then
set AppleScript'stext item delimiters to " "
set newname to text items of thename
set AppleScript'stext item delimiters to "_"
set name of thisItem to (newname as string)
set AppleScript'stext item delimiters to defDel
end if
end repeat
end tell
thanks in advance!