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