PDA

View Full Version : XCode - Cocoa-applescript question




djjasonsa
Feb 21, 2013, 10:11 AM
Hi All,

I am trying to create a simple Cocoa-applescript, however I am having issues with getting a Text Field or Label to display the output from a shell command.

I know this probably basic stuff but an help would be most grateful

Thanks



Red Menace
Feb 21, 2013, 11:32 AM
Is this an Xcode or AppleScript Editor project? Usually you would get the result from your shell script and put it into the text field using its setStringValue: (http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSControl_Class/Reference/Reference.html#//apple_ref/occ/instm/NSControl/setStringValue:) method, although bindings can also be used. What have you done so far?

djjasonsa
Feb 21, 2013, 11:50 AM
Thank you very much for the quick response.

Ap0ks
Feb 21, 2013, 03:50 PM
The text field you're trying to populate, have you changed it's behaviour from editable to selectable or none?

Your posted code works fine for me if the text field behaviour is set to editable. To make it work when the text field behaviour is set to selectable or none I had to put your code into the awakeFromNib method rather than an IBAction method, like so:
on awakeFromNib()
set ipAddress to (do shell script "ifconfig | grep -B 2 active | grep -E \"inet \" | awk {'print $2'}")
label's setStringValue_(ipAddress)
end awakeFromNib