Hello all,
I have this simple script which I would like to display a system info string as a NSTextField. The current window has a button and a NSTextField, where when I press the button, I would like the system info defined to display as the NSTextField
Let’s say:
-- Grab the current IP
property ipaddress : IPv4 address of (system info)
on clicked theObject
activate
if name of theObject = "getIPaddress" then
--- Right here I would like it to send the property above to a NSTextField
end if
end clicked
Is there a way to do this with NSTextField Label or with the Text Box? I would prefer the Label but if it works out much better with the Text Field, I am in no position to argue.
Hi,
welcome to MacScripter.
It’s not recommended, to use a property for gathering the system info.
Better assign the value to the property during the awake from nib, will finish launching or launched handler.
An editable text field and a label is actually the same thing, the appearance depends on the settings made in Interface Builder
try this, it requires a text field named “ipAddress” in a window “main”,
property ipaddress : ""
on awake from nib
set ipaddress to IPv4 address of (system info)
end awake from nib
on clicked theObject
if name of theObject = "getIPaddress" then
set contents of text field "ipAddress" of window "main" to ipaddress
end if
end clicked
Thank you StefanK for the quick response.
That sounds a lot better than when I defined the property on top. I was wondering what special applescript properties in Interface Builder does the text field have to be for the text to show up?
take a look at the documentation:
NSTextField
I seem to be having an issue with setting a NSTextField within a tab group within a Window. I set it to:
property ipaddress : ""
on awake from nib
set ipaddress to IPv4 address of (system info)
end awake from nib
on clicked theObject
if name of theObject = "getIPaddress" then
set contents of text field "ipAddress" of tab group 1 of window "main" to ipaddress
end if
end clicked
I’m afraid this throws an error telling me it cannot go after the identifier. Is the syntax of tab group 1 correct? Or would it be different than getting the property of the NSTextField?
If you have a tab named “IP” and you named the tab view “ipView” then it would look like this.
set contents of text field "ipAddress" of tab view item "IP" of tab view "ipView" of window "main" to ipaddress
Also, if you are not currently using Script Debugger by Late Night Software I would highly recommend it.
Anytime you cannot figure out what the syntax is in your AS Studio project use Script Debugger’s Explorer to find it.
This will save you much headache if you plan on doing any amount of AS Studio work.
Regards,
Craig
Thank you very much for the quick response Craig Williams.
I believed that is what I was missing, though I did get “the specific object is a property, not an element”. I see that this may be a bug from this post http://bbs.macscripter.net/viewtopic.php?id=24323. I will play with it and see what happens then. I also downloaded a trial of Script Debugger. It looks very nice, and I will write a few things with it to see how that works. Thank you very much for your input and your recommendation.