Buggy Script to change icon on selected folders

Hello Everyone, I am trying to write a script that asign a custom icon and spotlight comment to the selected folders.

I am newbie on applescript, I found that when I try to call the setIconAndComment handler from inside the loop it doesn’t work “says “I can’t continue setIconAndComent” , is it a concept error?

Thanks for your time


(*
DESCRIPTION: This Applescript asign a specified icon and spolight comment to the selected file
BUGs: It would filter only the folders from the selected files
*)
on setIconAndComment(estado, elemento)
	copy elemento as alias to targetFolder
	set passvariable to "Macintosh HD:Users:javito:Desktop:Iconos Estado:" & estado
	set tmpIcon to alias passvariable

	tell application "Finder"
		activate
		set tmpIconWindow to name of (open information window of tmpIcon)
	end tell
	tell application "System Events"
		tell application process "Finder"
			tell window tmpIconWindow
				keystroke tab
				keystroke "c" using command down
			end tell
		end tell
	end tell

	tell application "Finder"
		close window tmpIconWindow
		set targetWindow to name of (open information window of targetFolder2)
	end tell
	tell application "System Events"
		tell application process "Finder"
			tell window targetWindow
				keystroke tab
				keystroke "v" using command down
			end tell
		end tell
	end tell
	--Introduce el comentario
	tell application "Finder"
		close window targetWindow
		set comment of targetFolder2 to Status & "."
	end tell
end setIconAndComment

on open these_items
	tell application "Finder"
		repeat with i from 1 to the count of these_items
			set this_item to (item i of these_items)
			copy this_item as alias to targetFolder
			display dialog "Select Project's State" buttons {"Proyecto Actual", "Proyecto en el Limbo", "Proyecto Finalizado"} default button "Proyecto Actual"
			set projectStatus to button returned of result
			setIconAndComment(projectStatus, targetFolder)
		end repeat
	end tell
end open

Thanks, now works!! :smiley:

So, If I define a handler I should call it with the my prefix, what does it means exactly?

Thank you again Jacques, It is really nice to be helped so quickly :slight_smile: