Was working in Tiger but not in Leopard

Hi everybody, I’m sure this topic has been covered before but I just upgraded from 10.4 Tiger to 10.6 Leopard and while most of my scripts work so far, this one doesn’t. The error I get now is "Can’t get alias “Macintosh HD:Users:scyr:Desktop:my_Test_file.indd” of application “Finder”. Any idea why?

on open item_list
tell application “Finder”
activate
display dialog “String to insert:” default answer “”
set insertion to the text returned of the result
display dialog “After how many characters?” default answer “8”
set numero to the text returned of the result as number
repeat with this_item in item_list
set my_filename to get the name of this_item
set char to get every character of my_filename

		set inter_name to ""
		repeat with this_char in char
			if this_char does not contain "_" and this_char does not contain " " and this_char does not contain "'" and this_char does not contain "´" and this_char does not contain "`" and this_char does not contain "ˆ" and this_char does not contain "¨" then set inter_name to inter_name & this_char as string
			
		end repeat
		set internamecount to count every character of inter_name
		set new_name to (characters 1 thru numero of inter_name) & "_" & insertion & "_" & (characters (numero + 1) thru internamecount of inter_name) as string
		set the name of this_item to new_name
	end repeat
end tell

end open

I just tried your script and it works fine for me on 10.6. Try re-saving the script, perhaps?

Btw, you can simplify that a bit. String manipulation using text item delimiters is easy and gives the best performance:

on open item_list
	tell application "Finder"
		activate
		display dialog "String to insert:" default answer ""
		set insertion to the text returned of the result
		display dialog "After how many characters?" default answer "8"
		set numero to the text returned of the result as number
		repeat with this_item in item_list
			set my_filename to get the name of this_item
			
			set AppleScript's text item delimiters to {"_", " ", "'", "´", "`", "ˆ", "¨"}
			set inter_name to text items of my_filename
			set AppleScript's text item delimiters to ""
			set inter_name to inter_name as string
			
			set new_name to (text 1 thru numero of inter_name) & "_" & insertion & "_" & (text (numero + 1) thru -1 of inter_name)
			set the name of this_item to new_name
		end repeat
	end tell
end open

Hi,

this one’s calling for the Shell :wink:

set theString to "aFileName_ '´`ˆ¨sample.indd"
set cleanedString to do shell script "tr -d '_ '´`ˆ¨' <<< " & quoted form of theString

–Delete characters in string1 from the input

but I don’t no either a solution for your alias problem … sorry …

perhaps try to catch the error in your repeat loop:

try
				-- insert actions here
			on error the error_message number the error_number
				display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
			end try