Display System_profiler onto a textView

Hi

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_

end script

I pasted your code into a new app, and it worked fine for me. What is the error that you are seeing?

Ric

Thanks, here what I get:

2011-11-07 13:50:58.753 System Information[78288:a0f] *** -[System_InformationAppDelegate getSystemInfo:]: -[NSScrollView setString:]: unrecognized selector sent to instance 0x200653320 (error -10000)

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.

Ric

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

Ric

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.

Thank you.

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.