Sunday, December 17, 2017

#1 2017-11-25 01:05:31 pm

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

pre-populating a pulldown menu?

I'm a complete novice to Xcode; only slightly better with applescript.

I'm trying to take one of my older applescripts that runs fine with myriad popup dialogs taking user input, and port it over to Xcode applescript objective-C so that I can run the script from a single panel.

I already have a text field in the MainMenu.xib bound back to a property value in the form

Applescript:

property theValue: ""

that returns the input value. But, I'd like to get the same results from a pulldown menu of pre-populated items like you'd get from AS with:

Applescript:

set FruitList to {"Banana", "Kiwi", "Mango", "Coconut", "Pear"}
set FavoriteFruitAnswer to choose from list FruitList with title "Fruit Dialog" with prompt "What's your favorite fruit?" default items "1. Banana"

But, in a pulldown menu using NSPopUpButton in Xcode

Is this something simple I'm missing, or is it a complex concept to master?


Filed under: xcode, AS Objective-C

Offline

 

#2 2017-11-25 05:53:19 pm

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

Re: pre-populating a pulldown menu?

Add another property, and bind the popup's Selected Index or Selected Value.


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

Offline

 

#3 2017-11-26 09:18:01 am

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

Re: pre-populating a pulldown menu?

heh. like I said, I'm green. I guess my real question was how do you assign values to a button in the MainMenu.xib in the first place.

I never noticed the turndown arrow next to the item in the window sidebar hmm
Once I stumbled upon that, it was all downhill.

menu_item_values.jpg

Your suggestion of setting the pop up button to the value  or  index didn't fall on deaf ears though. that helped a lot.  thanks.

So, now I have the pulldown menu VALUES easily passed back to a variable in the AppDelegate. But, if I decide to pass the INDEX instead, what is the syntax in applescript.

For example, say I have my FruitList example above in AppDelegate. How would I map the index returned to those values?

Offline

 

#4 2017-11-26 06:18:04 pm

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

Re: pre-populating a pulldown menu?

cudaboy_71 wrote:

How would I map the index returned to those values?



0 would be Frankie Joe, 1 would mean Stevie Ray, and so on.


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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)