I’m a newbie and did search the past topics but was unable to find an answer to my issue. I’m currently trying to take input from a text field and store it as a string that I will later insert in a autogenerated .xml file. The most basic problem I’m having now is displaying the variable that contains the string. Everytime I reach the point of a dialog box displaying this variable, I get this error: Can’t make «class ocid» id «data kptr0000000080D9640002000000» into type string. (error -1700) I don’t know exactly what I’m doing wrong but assume it has something to do with the way I’m storing the string into another variable. I will paste the code below, if someone could at least point me in the right direction I would greatly appreciate it. Thanks,
Tim
script ID_XML_Creator_v1AppDelegate
property parent : class “NSObject”
– IB Outlets
property baseName1 : missing value
– IB Actions
on createXMLS_(sender)
set baseName1Value to baseName1's stringValue()
display dialog baseName1Value
end createXMLS_
Hi,
AppleScript’s class text/string and Cocoa’s NSString is not the same thing.
For display dialog NSString must be coerced to the AppleScript equivalent
.
set baseName1Value to baseName1's stringValue() as string
.
In AppleScriptObjc you better get used to coerce a lot. 
As soon as you use cocoa methods or objects you will need to coerce them to use them in plain AppleScript. For some strange reason the only coercion that doesn’t work is “as number”, always creates an error. Use as real or as integer, they work fine.
Good luck!
Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)
Thank you both so much. That was exactly my issue, and was able to finish the rest of my project. Thanks again…
I do have one more related question though. I’m now creating another option in my program to clear out all of the text entry fields. It seems as though no matter what I try, I’m not actually able to reset the text fields with input back to “”. I don’t need to change the applescript variable, I’m wanting to change the text that appears in the entry box on the user interface which I assume is the Cocoa Object.
I’ve tried:
set baseName1 to “” as string
set baseName1 to “”
and I’ve also tried
set clearTxt to “”
baseName1 setStringValue(clearTxt)
I’ve tried several snippets I’ve seen across the forums and can’t seem to make it work. Any direction you could provide would be greatly appreciated. Thanks,
Tim
Your syntax is incorrect here – in any cocoa method, you need an underscore for each argument that is passed. In the case of setStringValue you need one: setStringValue_(“”).
Also the object that is being sent the method, in this case baseName1, needs to be in the possessive form or you need to use “tell” :
baseName1’s setStringValue_(“”) or
tell baseName1 to setStringValue_(“”)
Ric
Looks like Ric replied same time I did! 
This method has a variable, so you need to add a _ at the end:
baseName1's setStringValue_(clearTxt)
and also since it’s an instance method you need to add the 's to your property linked in IB to tell it to use it’s own method. Don’t worry, easily fixed beginner mistake, we’ve all been through it in the beginning.
If you have a more complex method, you need to replace every colon with and underscore and then supply each variable in the same order in parentheses. So for example with this NSString method:
stringByReplacingOccurencesOfString:withString:
Becomes:
stringByReplacingOccurencesOfString_withString_(stringToSearch, stringToReplaceWith)
Class methods are different, but not that much harder.
Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)