check filename - capitalize if not

Hi all,

I have been running a script that renames a filename depending on its structure and also changes the filenames to capital letters. While it works most of the time, it seems to be stalling (or something) and its been missing files that are dropped into the folder. I have a 1 minute delay on the folder to make sure all the files are seen by the script but it still seems to be missing some.

So, what I am looking for some help with is - is there some type of loop I can kick in or should I add a check to another folder to check for the capital letters and kick it back to the first folder to start it again if the filename isn’t capitalized (and therefore has not been run through the script)?

Thanks!

Courtney

-------------------------------script below--------------------------------------------------

on adding folder items to thisFolder after receiving theItems
set {ASTIDS, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, “"}
set theItems to (list folder thisFolder without invisibles)
repeat with anItem in theItems
set theName to text 8 thru (length of anItem) of anItem
set itemPath to ((thisFolder as string) & anItem) as alias
set itemParts to every text item of theName as list
set partCount to count itemParts
if partCount = 8 then
set newName to (get item 1 of itemParts) & "

set newName to newName & (get item 2 of itemParts) & “"
set newName to newName & (get item 3 of itemParts) & "

set newName to newName & (get item 4 of itemParts) & “"
set newName to newName & (get item 8 of itemParts)
else if partCount = 7 then
set newName to (get item 1 of itemParts) & "

set newName to newName & (get item 2 of itemParts) & “"
set newName to newName & (get item 3 of itemParts) & "

set newName to newName & (get item 4 of itemParts) & “"
set newName to newName & (get item 7 of itemParts)
else if partCount = 6 then
set newName to (get item 1 of itemParts) & "

set newName to newName & (get item 2 of itemParts) & “"
set newName to newName & (get item 3 of itemParts) & "

set newName to newName & (get item 4 of itemParts) & “_”
set newName to newName & (get item 6 of itemParts)
end if
set newName to changeCaseOf(newName)
tell application “Finder”
set properties of itemPath to {name:newName}
end tell
end repeat
set AppleScript’s text item delimiters to ASTIDS
end adding folder items to

on changeCaseOf(thisText)
set the comparisonString to “abcdefghijklmnopqrstuvwxyz”
set the sourceString to “ABCDEFGHIJKLMNOPQRSTUVWXYZ”
set the newText to “”
repeat with thisChar in thisText
set x to the offset of thisChar in the comparisonString
if x is not 0 then
set the newText to (the newText & character x of the sourceString) as string
else
set the newText to (the newText & thisChar) as string
end if
end repeat
return the newText
end changeCaseOf

Model: G5
Browser: Firefox 3.5.3
Operating System: Mac OS X (10.4)

Hi,

the problem might be that you process always all files of the hot folder regardless of the number of added files.
Another problem is that the script throws an error if a file doesn’t match the conditions because the variable newName won’t be defined. Folder Action scripts stop silently when an error occurs.

This is an optimized version of your script, which processes only the new added files.
If the file name does not match the conditions the file will be only capitalized.


on adding folder items to thisFolder after receiving theItems
	repeat with anItem in theItems
		set theName to text 8 thru -1 of name of (info for anItem)
		set {TID, text item delimiters} to {text item delimiters, "_"}
		tell text items of theName
			set cnt to count it
			if cnt > 5 and cnt < 9 then
				set theName to (items 1 thru 4 & item cnt) as text
			end if
		end tell
		set text item delimiters to TID
		set capitalizedName to do shell script "/bin/echo " & quoted form of theName & " | /usr/bin/tr 'a-z' 'A-Z'"
		tell application "Finder" to set name of contents of anItem to capitalizedName
	end repeat
end adding folder items to

Stephan,

Thanks, I will try it out as soon as I get back in tomorrow and I appreciate your fast response!