on clicked theObject
set theName to text contents of "nameField" as string
get theName
display theName in "answerField" as string
end clicked
ok so here is my code it is just something so i can learn. I have an interface built that just has a text enter field called “nameField” and another field to display whatever the user types in the first field after clicking the button. Im getting an error that says “cant get type to reference” or something similiar. So all im asking is how to get text from a text field and display it into another text field.
on clicked theObject
if name of theObject is "copyButton" then --> "copyButton" is the name you've given to your button
set theText to (content of text field "nameField" of window "yourWindow") as string
set content of text field "answerField" of window "yourWindow" to theText
end if
end clicked
You should wrap the code for each individual button in an if/else block of it’s own, otherwise your app can have only one button. Also, I typically use the ‘content’ property, rather than the ‘contents’ property when referencing an object’s value. There are some cases where you MUST use the contents property, but there are also others where the contents property returns an unexpected value and causes errors that are sometimes hard to track down. And, make sure to reference the window that the objects are in, or you’ll get errors for that too.