I’ve tried every example I could find on this site before I posted this, I’m sure its something stupid.
I’m just trying to retrieve the currently selected title of an nspopupbutton using applescript and put it a variable.
Everything I’ve tried doesn’t do anything.
Can somebody steer me in the right direction
I’ve figured out all the other controls on my form but this one has stumped me.
I have even downloaded some example code and it didn’t work either.
i tried using:
set itemselection to NSpopupbutton’s titleofselecteditem()
This code just hangs when I run it.
cocoa applescript application
You’re doing 2 things wrong here. First, you are addressing the message (the method titleOfSelectedItem) to the NSPopupButton class instead of an instance of the popup button, and second, you didn’t capitalize the method name properly. You need to define a property for your button and set it to missing value. Then connect that in IB to your button. If you call your button myPopup, you would do this:
property myPopup:missing value
then somewhere in your code:
set itemSelection to myPopup’s titleOfSelectedItem()
Sorry I should have been more clear,
I do have an instance:
property stem_format1 : missing value
this instance is assigned to NSpopupbutton
then I try
set itemSelection to stem_format1’s titleofselecteditem()
display dialog itemSelection
The dialog box never opens. It seems to stop as soon as I try and read the titleOfSelectedItem()
When you say I didn’t capitolize the method name correctly do you mean the titleofselecteditem() should be titleOfSelectedItem()
OK I thought this might be a problem but everytime i type titleOfSelectedItem() xcode automatically changes it to titleofselecteditem(). Do you know why that is? I cant seem to make those capital letters stay.
Ric thanks alot for your time and help. This one is driving me nuts.
Yes, this is a problem in ASOC – if you type something wrong, it seems to remember it and won’t let you correct it. There are two solutions. You can spell it correctly with pipes around it and then compile : |titleOfSelectedItem|()
you can delete the offending letters, so: titlefelectedtem (I’ve deleted the lower case o,s and i), then close your program and xcode (you must close xcode not just your program), then reopen, type in the correct letters and compile.
Ric you are a Genius. That worked perfectly. Thank you for giving me my sanity back