For practice purpose, I am trying to get the system_profiler output to a textView. However, I am getting errorr regarding incorrect selector.
Could any one help me with this please. Also, would it be possible to prove Cocoa’s equivalent of the above UNIX command.
Thank you all.
Code:
script System_InformationAppDelegate
property parent : class “NSObject”
property textView : missing value
property theWindow : missing value
property theInfo : missing value
on getSystemInfo_(sender)
-- run the command to get info
set myString to do shell script "system_profiler"
textView's setString_(myString)
--theWindow's makeFileResponder_(me)
end getSystemInfo_
on applicationWillFinishLaunching_(aNotification)
textView's setTextContainerInset_({10.0, 10.0})
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
You really should pay more attention to your error messages – the answer is right there: -[NSScrollView setString:]:
You connected your IBOutlet to the scroll view instead of the text view.
As far as replacing the shell script with cocoa methods, I’m not sure there are any to get all the info that you get from the system profiler.
do shell script can be replaced with NSTask, but I guess the benefit is quite poor in this case.
Another way is to parse IORegistry with IOKit, this is very smart for single values like mouse or trackpad battery status
or the parameters of a hard disk volume, but it’s not worth the effort for the entire information
I took a second look at the IB and yes, it was connected to the ScrollView. My eyes are not doing the job these days. I re-connected the TextView property to the TextView and it works well.
The one issue with do shell script is that the escape key cancels any such call that is running, even if you have it mapped to something else. So if you have a process that takes time, make sure there’s no chance the user will press escape while it’s running.