On or about 6/4/06 3:14 PM, thus spake "Ari Bader-Natal"
<email@hidden>:
>
> "performSelector:withObject:afterDelay:" sounds like a useful resource, but
> I'm having trouble
> tracking down an example that uses it via AppleScript. I've tried variations
> on the following
> example without success:
>
> set b to (button 1 of window 1)
> call method "performSelector:withObject:afterDelay:" of b with parameters
> {"performClick:", id
> of b, 1}
>
> What's the correct way to do something like this?
I said that the Cocoa way out of exactly the same difficulty you're having
is to use performSelector:withObject:afterDelay:. I didn't mean to imply
that you could use "call method" to call
performSelector:withObject:afterDelay: directly. The difficulty is that the
first parameter needs to be a selector (not a string), and I don't know how
you'd obtain that from AppleScript. It is much easier, in my view, to use
"call method" to call a Cocoa method (belonging to a class that you write,
yourself) that calls performSelector:withObject:afterDelay:.
So, for instance you could say this:
call method "tellObject:performSelector:withObject:afterDelay:" of class
"DelayedPerformer" with parameters {window of theObject,
"makeFirstResponder:", text field 2 of window 1, 0.1}
where "DelayedPerformer" refers to a class you've written that has a class
method that goes like this:
+ (void) tellObject:(id)target performSelector:(NSString*)selectorString
withObject:(id)obj afterDelay:(float)delay {
[target performSelector:NSSelectorFromString(selectorString)
withObject:obj afterDelay:delay];
}
m.
>> Date: Fri, 02 Jun 2006 12:42:57 -0700
>> Subject: Re: Change focus to table view.
>>
>> The problem is that you're changing the first responder while the return key
>> is still being processed. Thus the framework is still messing with the
>> business of who's got the focus and restores it to the text field as part of
>> its own cleanup, which takes place after you've changed it. The solution is
>> to use "delayed performance" so that the change of first responder you're
>> after doesn't happen until *after* we return completely from the clicked
>> handler. You can do this with an idle handler, probably; the Cocoa way is to
>> call performSelector:withObject:afterDelay:, which is a lot easier.
>>
>>
> <http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/N
> SObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/performS
> elector:withObject:afterDelay:>
>
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide - Second Edition!
http://www.amazon.com/gp/product/0596102119
Take Control of Word 2004, Tiger, and more -
http://www.takecontrolbooks.com/tiger-customizing.html
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden
This email sent to email@hidden