Oh the frustration of AppleScript. It haunts me.
I’m trying to use a method to replace some elements in a string. I have my handler at the bottom of the script, and I’ve read that the handler has full scope over the whole script. Not sure what’s happening.
[format]Result:
error “Finder got an error: Can’t continue replace_chars.” number -1708[/format]
This handler works in small test scripts so I’m not sure what is going on:
on replace_chars(this_text, search_string, replacement_string)
-- replace_chars(message_string, "string_to_be_replaced", "replacement_string")
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
I have the application of this handler parked inside two tells:
tell application "iTunes"
--blah blah blah
tell application "Finder"
set myVar to replace_chars(myFolder, " ", "_") -- this is where it happens
end tell
on replace_chars(...see above for handler...)
end replace_chars
end tell
myVar doesn’t get set for some reason. Events feedback states that a proper myFolder parameter is submitted. So I’m not sure why it isn’t modified. The error, which I had to research (why is this even needed?):
[format]-1708 The script doesn’t understand the message. The event was not handled.[/format]
Any help appreciated. I find AS truly difficult to get through.