really basic radio button help?

This is my first attempt at xcode, so please excuse the dumb question. After searching the developer site and hacking on this for countless hours I give up. How do I get which radio is selected in a radio group using applescript?

I’ve tried endless variations of the following code:

display dialog title of current cell of matrix "myradios"

the error message I get is:

Can’t make «class titl» of «class curC» of «class matT» “myradios” into type reference. (-1700)

I added “as string” the the end for fun and got the same error with a different ending “into type string”.

Arggg

Ahhh… “get”. One of the many variaitions I tried did include window “windowname” – but, I never used “get”. “get” must be the applescript word for please? :slight_smile:

Thanks for the help!

That’s a good point. In most AppleScripts, get seems to be optional. Just when is get really necessary, and why?

Using “get” is not required in applescript. It is implied if left out, and is supported only to allow the syntax to be more human-readable. Writing get everywhere is syntactically redundant, but can be a good tool when getting used to applescript or when trying to clarify code. I never write get into my own code, and always cut it out when I use code I’ve found somewhere else… just a habit of mine, but illustrates that it is unnecessary to use and is merely a matter of preference.

j

Good, that’s what I thought, and I’ve never used “get” anywhere.

That can’t be right. When I remove “get” from the script, I get NSReceiversCantHandleCommandScriptError (4) – put it back, and everything’s copasetic. I can see how it might make the syntax more human readable, but in this case it is required or the script bombs.

Since “get” is “assumed”, then perhaps in this case the code is ambiguous. If I don’t explicitly command “get”, could applescript be incorrectly assuming a different command?

Actually, it can… but you must account for some differences in how you reference items in applescript studio versus how you’d handle them in straight-up applescript. For example, when you reference the title of something (like a button) in applescript, it is best to ensure that you coerce the value you’re referencing explicitly into a string, so as to avoid referencing errors. When you say… “title of someObject”, what you’re usually getting is a pointer to the items title… NOT the string value of the title itself. Rather that trusting that “get” will always return a string (which some references do not always do… like ‘contents’ vs. ‘content’), you should explicitly use “… as string” to tell the script that you want the string value of the title. This seems like trivial stuff, but I think that this is the best way to approach this kind of situation. It is really clear what you’re after, and if you throw an error it’s more predictable as to what the problem is. If you change the code to reflect this coersion, you’ll get something like…

display dialog ((title of current cell of matrix "SomeMatrix" of window "SomeWindow") as string)

Even better, set a variable to the title’s string value, then use that instance in your code without ‘getting’ the title repeatedly for compound if/else statements…

set currCellTitle to ((title of current cell of matrix "SomeMatrix" of window "SomeWindow") as string)
display dialog currCellTitle

j

Interesting combination… If I add “as string” to the end of the code without using get, it works. If I use get without “as string” it also works. Strange…