noob - error - where did I go wrong, please?

on open ThisFile
	set AppleScript's text item delimiters to ":"
	set InText to the last text item of (ThisFile as text)
	set ParentFolder to ((text items 1 thru -2 of (ThisFile as text)) as string) & ":"
	set AppleScript's text item delimiters to ""
	set InTextList to every character of InText
	set OutText to ""
	repeat with the_character in InTextList
		if ¬
			the_character is greater than or equal to "1" and the_character is less than or equal to "9" or ¬
			the_character is greater than or equal to "a" and the_character is less than or equal to "z" then
			set OutText to OutText & the_character
		else
			set OutText to OutText & "_"
		end if
	end repeat
	set OutText to OutText as Unicode text
	set ThisFile to ThisFile as Unicode text
	set ParentFolder to ParentFolder as Unicode text
	tell application "Finder"
		set the name of ThisFile to ParentFolder & OutText
	end tell
end open

I’m a clueless noob with only a week of experience. A hint would be appreciated.

Model: G5
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

remove this line

   set ThisFile to ThisFile as Unicode text

=)

Hi,

renaming a file partially with a string path doesn’t work because colons are not allowed in file names.
Assuming you want only filter the special characters, try this

on open TheseFiles
	repeat with ThisFile in TheseFiles
		set {name:Nm, name extension:Ex} to info for ThisFile
		if Ex is missing value then set Ex to ""
		if Ex is not "" then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
		set OutText to ""
		repeat with the_character in (get characters of Nm)
			if the_character is in "0123456789abcdefghijklmnopqrstuvwxyz" then
				set OutText to OutText & the_character
			else
				set OutText to OutText & "_"
			end if
		end repeat
		tell application "Finder" to set the name of contents of ThisFile to OutText & "." & Ex
	end repeat
end open

I see it now! Gosh, have I a lot to learn.

Thank you so very much, Stefan.

John