NSComboBox: How to deselect an item

Hi everybody,

I have a NSComboBox and any time a selection is made within it, the selection populates the NSComboBox’s principal placeholder as expected.

What I’d like to accomplish is that anytime a selection is made, the principal placeholder gets empty immediately.

These are the approaches I tried so far but all of them end thowing an error message:

– 1 –
property myComboBox : missing value

on myComboBoxClick_(sender)
myComboBox’s deselectItem(myComboBox’s indexOfSelectedItem)
end myComboBoxClick_

Yields the following error message:

-[NSComboBox deselectItem]: unrecognized selector sent to instance 0x10071af10 (error -10000)

– 2 –
tell myComboBox
deselectItem(myComboBox’s indexOfSelectedItem)
end tell

Yields the same error message as above:

#-[NSComboBox deselectItem]: unrecognized selector sent to instance 0x10071bc20 (error -10000)

I’m sorry for this pretty basic question but I couldn’t find out how to use this function correctly:

func deselectItem(at index: Int)

Thank you in advance.

Marius

I’ve made a small progress but still not good enough:

I’ve replaced ‘deselectItem’ by ‘deselectItemAtIndex’ and surround the statement into ‘[]’, like this:

[format][prComboBox’s deselectItemAtIndex:(prComboBox’s indexOfSelectedItem)][/format]

The good thing is that the placeholder gets clear
The bad thing is that at the end a new error message is genarated:

[format]No result was returned from some part of this expression. (error -2763)[/format]

I know this is a very simple question, but for me is difficult to see what is the problem because I’m starting with AppleScript and I do not have any knowledge of Objective C.

Thank you in advance :slight_smile:

This works.


indexOfSelectedItem()


			set aInd to aCombo's indexOfSelectedItem()
			aCombo's deselectItemAtIndex:(aInd)

Model: MacBook Pro 2012
AppleScript: 2.7
Browser: Safari 13.0.1
Operating System: macOS 10.14

What a dummy mistake! :o

I forgot to add the ‘()’ in the function call…

Thank you for your help, Maro-san

Mariano R.