Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Intelligent

macrumors 6502a
Original poster
Aug 7, 2013
922
2
Im trying to make a code where AppleScript sets a variable from the text returned of a NSTextField

Code:
set variable to text returned of (NSTexTField)

How would i do so that my AppleScript code recognizes that specific NSTextField and can set the text in it to a Variable?
 

Red Menace

macrumors 6502a
May 29, 2011
583
230
Colorado, USA
What OS/Xcode versions are you using? I am going to guess that you are using AppleScriptObjC in an Xcode project, in which case you would have the text field connected to a property, where you can use the various methods of the NSTextField class (and its parents) such as stringValue:

Code:
property myTextField: missing value -- connected to the text field in IB

--
    set whatever to myTextField's stringValue() as text
 

chown33

Moderator
Staff member
Aug 9, 2009
10,932
8,786
A sea of green
Here's a simple tutorial that shows the basics using an outlet, then a more advanced version using bindings:
http://www.peachpit.com/articles/article.aspx?p=1942301

It creates an input text field where you type your name. You then press a button to display an alert with the entered name.

As with all tutorials, I recommend completing the tutorial exactly as given. Only after completing it and getting a working result should you strike out on your own to apply what you've learned.

Found by googling: cocoa applescript
 

Intelligent

macrumors 6502a
Original poster
Aug 7, 2013
922
2
What OS/Xcode versions are you using?

OS X 10.9.5, Xcode 6.1.
Thank you for that.

A very similar question (if you don't mind).

I'm using this code to run a unix script, currently i have it like this

Code:
set variable to textField's stringValue() as text
    set mscript to do shell script "command " & variable
    display dialog mscript

And instead of "displaying dialog" i want it to display the output on another text field.
I did like you said and added

Code:
    property textField2 : missing value
and then i connected it to App Delegate in IB.

However, i can not figure out how display the output on that textfield. Currently i use the display dialog script which works fine.
 
Last edited:

Red Menace

macrumors 6502a
May 29, 2011
583
230
Colorado, USA
If the text returned by your shell script is fairly short a text field will be fine, but for anything more than the width of your text field (especially if there are multiple lines) you may want to use a text view instead. For a text field, you would use something like:

Code:
textField2's setStringValue:mscript

Take a look at the NSTextField Class Reference that I linked to earlier for the various methods available.
 

Intelligent

macrumors 6502a
Original poster
Aug 7, 2013
922
2
If the text returned by your shell script is fairly short a text field will be fine, but for anything more than the width of your text field (especially if there are multiple lines) you may want to use a text view instead. For a text field, you would use something like:

Code:
textField2's setStringValue:mscript

Take a look at the NSTextField Class Reference that I linked to earlier for the various methods available.

Alright thank you, i will try and read it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.