I am trying to use “call method” to call the Cocoa API, but no matter what I do, it simply doesn’t do anything at all. I am using 10.3.5 and Xcode 1.5, so I would think that my environment should be up to date enough to use “call method”.
Can anybody please shed some light on this, here is my most recent test code …
on clicked theObject
local InputString, TrimmedString, NSCharSet
if the name of theObject is "TrimButton" then
log "trim button clicked"
set NSCharSet to call method "whitespaceAndNewlineCharacterSet" of class "NSCharacterSet"
set InputString to (contents of text field "InputString" of window "Main")
log "InputString: <" & InputString & ">"
set TrimmedString to (call method "stringByTrimmingCharactersInSet:" of class "NSString" with parameter NSCharSet)
log "Trimmed: <" & TrimmedString & ">"
end if
end clicked
the output I am getting is this:
[Session started at 2004-12-12 01:11:57 +0900.]
2004-12-12 01:12:09.182 CocoaTrimStringExample[8214] “trim button clicked”
2004-12-12 01:12:09.242 CocoaTrimStringExample[8214] “InputString: < this is a test >”
and then after about a one second delay an error box pops up that says:
AppleScript Error
The variable TrimmedString is not defined. (-2753)
Strange as it may seem, this error pops up even if I define TrimmedString as a property with a given value, ie “” or “foobar”. In other words, the only effect that “call method” seems to have is to undefine variable TrimmedString. Oooooops!
I’d appreciate if somebody could give me a few hints on how to use this facility, the documentation on this is so lousy it may as well not be there at all and what’s out there on the web when googling for “call method” is not of any learning value either.
I have a similar case here. Using copy instead of set doesn’t change the error I get.
Kevin, your thoughts would be appreciated… if you’re still on this forum or somebody else wants to help, I’d be very happy.
My scenario:
set newRect to {398.0, 336.0, 878.0, 718.0}
-- set newRect to make new "NSrect" call method "frame" of window "Main"
set newMask to 0 -- as integer
set newBuffer to 0 -- "NSBackingStoreRetained "
set newDefer to "NO" -- as boolean
set NSWindow to call method "alloc" of class "NSWindow"
(* here's the similar part *)
--copy (call method "initWithContentRect:styleMask:backing:defer:" of NSWindow with parameters {newRect, newMask, newBuffer, newDefer}) to newWin
newWin to (call method "initWithContentRect:styleMask:backing:defer:" of NSWindow with parameters {newRect, newMask, newBuffer, newDefer})
--> Can't get window id 1. (-1728)
I have also tried this variant:
-- set NSWindow to call method "alloc" of class "NSWindow"
-- copy (call method "initWithContentRect:styleMask:backing:defer:" of class "NSWindow" with parameters {newRect, newMask, newBuffer, newDefer}) to newWin
set newWin to (call method "initWithContentRect:styleMask:backing:defer:" of class "NSWindow" with parameters {newRect, newMask, newBuffer, newDefer})
-- when referencing newWin --> The variable newWin is not defined. (-2753)
Maybe this post hasn’t been solved because it’s in O5X and not ASS/XCode board.