Help with Error

I wrote several ASOC scripts years ago and have recently found a need for them. but I’m getting an error that I can’t track down. Even the simplest things have me pulling my hair out. For example this script is giving me the following error. Is there a change or a deprecation I’m not aware of? Thanks for your help.

use AppleScript version “2.4”
use framework “Foundation”
use scripting additions

set theStr to “TEST” as string
set nameFix to my lowerStr(theStr)

on lowerStr:theStr
set myStr to current application’s NSString’s stringWithString:theStr
return (myStr’s lowercaseString) as string
end lowerStr:

Result:
error “*** -[BAGenericObjectNoDeleteOSAID lowerStr]: unrecognized selector sent to object <BAGenericObjectNoDeleteOSAID @0x6000006e31c0: OSAID(1) ComponentInstance(0x830004)>” number -10000

ChuckH2. I don’t think you can mix parameter types like that. The following uses a positional parameter and works. BTW, you use “my” when calling the handler; this is only necessary if it’s in a tell statement.

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

set theStr to "TEST" as string
set nameFix to lowerStr(theStr) --> "test"

on lowerStr(theStr)
	set myStr to current application's NSString's stringWithString:theStr
	return (myStr's lowercaseString) as string
end lowerStr

The AppleScript Language Guide discusse the different types of parameters at:

https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_about_handlers.html#//apple_ref/doc/uid/TP40000983-CH206-CJBIDBJH

peavine, thanks so much. Sometimes the simplest of errors take me the most time to track down.

The real reason your code doesn’t work is not in type mixing, but because you define a handler in the form of a main script method and then try to call a plain AppleSript handler with positional parameters that your main script doesn’t have.

That is, when you define a method, you must call the method, not the positional handler. And, in this case, the keyword my or its is required. So that the AppleScript interpreter knows that this is a method of your script (which, by the way, is a class, like any other AsObjC class).


use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

set theStr to "TEST" as string
set nameFix to my lowerStr:theStr -- THIS

on lowerStr:theStr
	set myStr to current application's NSString's stringWithString:theStr
	return (myStr's lowercaseString) as string
end lowerStr: