If you look at the NSPopUpButton documentation , you can see all the methods you can name and what they inherit from. In the Getting User Selection section, you have:
β selectedItem β titleOfSelectedItem β indexOfSelectedItem β objectValue
Of course, these are all methods, so if you want to get the index of the selected value, you must call if you want:
set my_index to myPopup indexOfSelectedItem()
Looking at the indexOfSelectedItem entry in the docs:
indexOfSelectedItem Returns the index of the item last selected by the user. - (NSInteger)indexOfSelectedItem Return Value The index of the selected item, or -1 if no item is selected.
We get an overview of the function from above, and then using the function, and finally a description of the return value. This tells us that indexOfSelectedItem does not accept any parameters (if it would look like - (NSInteger)indexOfItemWithTitle:(NSString *)title ). The return value on the left will be NSInteger, NOT Applescript Integer. Although Applescript may be able to handle it the same way, in some situations this may give you problems. The solution is to never consider NSString as an AS String and never consider NSInteger as an AS Integer. To do the conversion, we would have to change it to an AS string, and then to an AS integer:
set my_index to ((myPopup indexOfSelectedItem()) as string) as integer
So for your code, if it looks like this, you can use either indexOfSelectedItem or titleOfSelectedItem
source share