Display Terminal output in text field

Is there any way to display the output of a Terminal command (from do shell script) in a text view object in AppleScript Studio?

Thanks!

Hi

Something like the below maybe?

on clicked theObject
	if name of theObject is "BUT1" then
		do shell script "uptime"
		set _Result to the result
		set contents of text field "RESULT" of window "main" to _Result as text
	end if
end clicked

Budgie

That works awesome. The only problem is that the command I am trying to use (“lspci -nn”) does not work with do shell script, since its not a standard command but a OS X port of a Linux utility that is installed on the system. I get a “command not found” or something similar. Any other ways to do this command with administrator privileges?

maybe try saving your (“lspci -nn”) command as a executable, say TEST.sh file and have your script call it, not sure
if this is the right way to go or not, worth a crack though.

on clicked theObject
	if name of theObject is "BUT1" then
		do shell script "/Users/BUDGIE/Desktop/TEST.sh" with administrator privileges
		set _Result to the result
		set contents of text field "RESULT" of window "main" to _Result as text
	end if
end clicked

Budgie

Tried it and I got the same error. The problem is because do shell script only uses the #!/bin/sh interpreter (doesn’t accept foreign binaries)…have to find a way to execute the script in the background without using do shell script…

It seems more likely that your lspci binary is not in the default, limited ˜PATH’ that do shell script provides to its shell (not a problem with the shell not working with “foreign binaries”). If a program can be run via Terminal, it can be run with do shell script (though you might have to use something like expect to provide ˜tty’ access for some interactive-only programs).

If a bare “lspci” works in a Terminal window, you can use “which lspci” or “type lspci” in the same Terminal window to find the full path to the lspci binary. Try invoking it with the full path to lspci on your system: do shell script “/opt/bin/lspci” (or use whatever which or type shows instead of /opt/bin). In some instances (probably not this one), you might need to augment the PATH environment variable (say because the program you are invoking wants to use other programs from the same directory): do shell script “PATH="$PATH:/opt/bin" lspci”.

All this assumes that your lspci binary really was ported and compiled for Mac OS X and not just copied from a Linux machine. The latter would require that Mac OS X emulate Linux. While this is not impossible (Linux, FreeBSD and other x86 Unix-like systems can often emulate each other, within limits), I have never heard of anyone actually doing it on Mac OS X (not that I have sought such emulations, everything I have ever needed has already been sufficiently ported to just build it “out of the box”).

Thanks! I’ll try that soon :slight_smile: LSPCI was ported from linux to OS X here:

http://x86dev.org/forum/index.php?topic=307.msg2754

The binary is installed in /usr/local/bin as I remember, I’ll double check that and report back later.

OK, so the first part works fine, but the second part where you set the contents of the text view is not working. OK, so I created a new window and named it “lspcioutput” in the AppleScript Inspector. Then I made a text view in that window called “output”. I associated both window and text view with my lspci.applescript file. Here is the code:


on clicked
if the name of theObject is equal to "runlspci" then
		do shell script "PATH=\"$PATH:/usr/local/bin\" lspci -nn"
		set _Result to the result
		set contents of text view "output" of window "lspcioutput" to _Result as text
end if
end clicked

The first part works fine, the “set contents of text view “output” of window “lspcioutput” to _Result as text” doesn’t work. I get this error:


Any solutions?

Thanks!

EDIT: Never mind, solved. All I had to do was add “of scroll window”


set contents of text view "output" of scroll view "output" of window "lspcioutput" to _Result as text

And it worked :slight_smile: