Call Method for Text Completion....

I just discovered AppleScript’s “call method” and have been working with it successfully.

I’d like to be able to implement a “complete:” method on a NSTextField, NSTextView, or NSTokenField.

I’ve tried this:

on keyboard down theObject event theEvent
call method “complete:” of (text field “bigtext” of window of theObject)
end keyboard down

and many variations, to no success.

I’d also like to define the array of values from which the index of possible values derives (like Mail.app or Safari address bar)

Here’s what the Apple docs say:

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSTextView.html#//apple_ref/doc/uid/20000373-BBCEDDCG

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSTokenField.html#//apple_ref/doc/uid/TP40001579-BAJIFAGA

Thanks! :slight_smile:

Methods whose name ends in a colon need a parameter, and for this one the parameter is (id)sender.

Many times the id of the sender does not matter, and in Cocoa you can simply pass a nil. I have found that (at least some) methods requiring a sender parameter will work by passing “missing value” as the parameter.

So this works:
call method “makeKeyAndOrderFront:” of window 2 with parameter missing value

Try that sort of thing with the “complete:” method.

Thanks!

Here’s what I tried:


on changed theObject
	call method "complete:" of (text view 1 of window 1) with parameter missing value
end changed


on changed theObject
	call method "complete:" of window 1 with parameter missing value
end changed


on changed theObject
	call method "complete:" of (text field "textfield" of window "main")  with parameter missing value
end changed

… and several other variations with different event handlers.

It didn’t work. How do you find the id of the sender (maybe that needs to be specified?)

I think this method (text auto-completion) is one that is very usable and something that many users expect now. It would be cool to get it figured out for AppleScripters!

Thanks so much for your insight.

I’ve been away for a few days, and have been thinking about this, and now I am confused about what you want to do.

I tested completion with several of my own AppleScript Studio apps, and completion works by default…in both an NSTextView and an editable NSTextField. As in any other Cocoa app, just type part of a word, then ESC or F5 causes a bunch of completion options to pop up and you can choose one and hit return. (I guess this only works with OS 10.3 or above…)

Do you want to modify or replace the list of options? If so you are going to have to write some objective-C code (i.e. your own custom call method). This is most likely doable, IF you want to start learning objective-C. But it won’t be particularly easy.

My own AppleScript Studio apps have lots of custom call methods; there are just a lot of things you cannot easily do directly from an AppleScript.

How do i do this?

i would like to give a user a custom list of options, but i don’t know obj-c. Help?

Thanks,

gecko

Have you looked at NSComboBox (found in the Cocoa Text Controls palette in Interface Builder)? It can be set to complete from its list of items. Just enable the checkbox ‘completes’ in the inspector in IB.

Wow!

I posted that message about six months ago, and I just came back to MacScripter to browse the forums, and lo and behold, I saw our conversation on the front page!

Thanks for your suggestions.

The ultimate solution was to go into Objective-C and use that.

I’ve been learning Cocoa and Objective-C, as well as playing with other scripting environments like PyObjc (using Python to build Mac programs). If anyone here has the desire and inkling to jump into Cocoa, do it. Give it a try, and don’t give up. It’s daunting at first (for me, anyway), but it’s possible, and there will be a point where it clicks (many people say this).

Thanks again!

Cheers,
Peter