Monday, December 18, 2017

#1 2017-11-27 02:58:23 pm

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

preselecting a popup item generated from ASOC

I have an NSpopupbutton that is populated from the appdelegate to the MainMenu.xib like:

Applescript:


property theSelection: "Blue Set"

on applicationWillFinishLaunching_(aNotification)
thePopup's removeAllItems()
set setList to {"Orange Set", "Green Set", "Blue Set", "Yellow Set", "Black Set"}
thePopUp's addItemsWithTitles_(setList)
end applicationWillFinishLaunching_


where theSelection is the value of the item selected that gets passed back to the appdelegate

I can set theSelection to "Blue Set" as above, and it works as expected; that is if the popup button is not touched by the user, the script handler (a 'Go' NS button is clicked) doesn't pass anything back to appdelegate, and the pre-existing variable declaration is used.

But, is there any way to get the NSPopupbutton to show a pre-selected value that may be in the middle of the list? As it stands, even though I can pre-define the variable in the appdelegate, the first item (Orange Set) of the NSPopupbutton is always displayed when run. I can't hard-code it in the .xib because the button's items don't exist until they are run in applicationWillFinishLaunching_

Offline

 

#2 2017-11-27 05:41:39 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: preselecting a popup item generated from ASOC

cudaboy_71 wrote:

is there any way to get the NSPopupbutton to show a pre-selected value



Use -selectItemWithTitle:.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2017-11-27 08:40:48 pm

cudaboy_71
Member
Registered: 2014-03-04
Posts: 20

Re: preselecting a popup item generated from ASOC

adding either

Applescript:


thePopup's selectItemAtIndex_(28)

or

Applescript:


thePopup's selectItemWithTitle_("Some Item's Title")

after the popupbutton's items were created did the trick.

thanks again.

Last edited by cudaboy_71 (2017-11-27 08:43:09 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)