Friday, January 28, 2022

#1 2021-10-24 07:22:19 pm

ChuckH2
Member
Registered: 2019-03-04
Posts: 4

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

Last edited by ChuckH2 (2021-10-24 07:22:53 pm)

Offline

 

#2 2021-10-24 07:45:40 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1218

Re: Help with Error

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.

Applescript:

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/arc … 6-CJBIDBJH

Last edited by peavine (2021-10-24 08:23:42 pm)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#3 2021-10-24 10:44:44 pm

ChuckH2
Member
Registered: 2019-03-04
Posts: 4

Re: Help with Error

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

Last edited by ChuckH2 (2021-10-24 10:45:09 pm)

Offline

 

#4 2021-10-25 04:28:20 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2208

Re: Help with Error

ChuckH2 wrote:

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


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).

Applescript:


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:

Last edited by KniazidisR (2021-10-25 04:37:51 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)