Sample Header Ad - 728x90

How to tell Applescript to call a Fondation's class's init?

0 votes
1 answer
67 views
A subquestion could be: how to find the AppleScript name of a class's instances? Context: I use the following to access NSTimeZone variables and apply methods.
use scripting additions -- essential to use (current date) with framework "Foundation"
use framework "Foundation"
    
tell class "NSTimeZone" of current application to resetSystemTimeZone()
    
set aTZ to current application's NSTimeZone
set localZone to aTZ's localTimeZone()
set defaultZone to aTZ's defaultTimeZone()
set aDate to (current date)
    
defaultZone's |name|() as string
defaultZone's abbreviation as string
defaultZone's abbreviationForDate:aDate
defaultZone's daylightSavingTimeOffsetForDate:aDate
defaultZone's secondsFromGMT()
defaultZone's secondsFromGMTForDate:aDate
etc. In Apple documentation , the last line above intended for SWIFT describes the use like this: func secondsFromGMT(for aDate: Date) -> Int It was hard to find the correct formulation for Applescript (secondsFromGMTForDate:aDate) but I figured it out. What I cannot conceive though is how to call an initializer like these ones described for SWIFT:
init?(name tzName: String)  
convenience init(forSecondsFromGMT seconds: Int)
Based on the previous pattern I tried all kind of formulations like these:
defaultZone's initWithName:"America/Toronto"  
tell defaultZone to initName:"EST"  
tell defaultZone to initNameString:"EST"  
tell defaultZone to initTzName:"EST"  
tell class NSTimeZone of current application to set SecondsFromGMT to 3600  
tell defaultZone to initforSecondsFromGMT:3600   
tell defaultZone to init:forSecondsFromGMT  
defaultZone's initNameString("EST")
...and many other variations. I always get an error like this:
error "-[_NSSwiftTimeZone initWithName]: unrecognized selector sent to instance 0x7fc514913750" number -10000
In fact I get the same error even if I write something like
tell defaultZone to playPiano:"EST"
so I get it that I don't have the right name (selector) for the call. And maybe not the right way to call either. On top of that, case matters in the names. What is the correct way to do it? Is there a way to list the instances, variables, methods, functions of an NS class as they are referred to in Applescript?
Asked by Recycleur (3 rep)
Oct 26, 2023, 04:23 AM
Last activity: Oct 26, 2023, 04:08 PM