Monday, July 26, 2021

#1 2003-08-18 05:47:27 pm

obedortiz
Member
Registered: 2003-02-12
Posts: 7

How to get results from do shell script

I am trying to get results from a do shell script. If I run a do  shell script, is it easy to just get the results displayed in the terminal? How would you go about it?

is it possible to just  set variableName to a result of a doshell script?

Offline

 

#2 2003-08-18 06:16:08 pm

tugboat666
Member
From:: Marysville, OH
Registered: 2003-01-21
Posts: 92

Re: How to get results from do shell script

Yes, just set a variable to the result of the shell script as follows:

set the_script to "echo Hello World"
set the_result to do shell script the_script
display dialog the_result

HTH

Offline

 

#3 2003-08-18 06:18:31 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: How to get results from do shell script

If you want the result displayed in the terminal.app, use the "do script" command in a tell block e.g.,

Applescript:

tell application "Terminal"
   activate
   do script "date"
end tell

Using the "do shell script" command invokes the "sh", which will not open a terminal.app window e.g.,

Applescript:

do shell script "date"

The result will show up in the 'Results' window of your Script Editor.
If you want to diaplay the result in a dialog window via AppleScript, you can try this...

Applescript:

set x to do shell script "date"
display dialog x


One mans trash is another mans treasure


Filed under: terminal

Offline

 

#4 2003-08-18 06:33:22 pm

obedortiz
Member
Registered: 2003-02-12
Posts: 7

Re: How to get results from do shell script

Thanks! that really helps. I got one more question related to this

say I launch an application through the "do shell script" through applescript. How would I then send commands to that application through applescript? for example telling it to quit.

Offline

 

#5 2003-08-18 06:50:38 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: How to get results from do shell script

I'm not sure I understand what you are trying to do. What application are trying to launch via "do shell script"? Why are you using AppleScript to run a "do shell script" to launch an application? Please post an example of the code you are using, there are way too many unknowns to try to help you.


One mans trash is another mans treasure

Offline

 

#6 2003-08-18 07:04:32 pm

obedortiz
Member
Registered: 2003-02-12
Posts: 7

Re: How to get results from do shell script

what I'm trying to do is be able to open an application like pico and be able to manipulate it through a gui I am creating with applescript studio and also be able to see the status of it through my gui. So I want to be able to send a command though my gui to it once it is already running to change preferences and such and get the results displayed in my gui.

Offline

 

#7 2003-08-18 07:35:36 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: How to get results from do shell script

You might not be able to do that via AppleScript...

Here's some info from Apple...

Q: How do I control an interactive tool like ftp or telnet with do shell script?

A: The short answer is that you don't. do shell script is designed to start the command and then let it run with no interaction until it completes, much like the backquote operator in most Unix shells or the system call in awk and Perl. However, there are ways around this. You can script Terminal and send a series of commands to the same window (though this only works in Mac OS X 10.2 and later), or you could use a Unix package designed for scripting interactive tools, such as expect. Also, many interactive commands have non-interactive equivalents. For example, curl can substitute for ftp in most cases.


http://developer.apple.com/technotes/tn2002/tn2065.html

I tried using

Applescript:

do shell script "cd $HOME;pico >> testtext; echo some text"

which will create the file named "testtext" in the home directory, but the contents of the file are the error message "Environment variable TERM not defined!"


One mans trash is another mans treasure

Offline

 

#8 2003-08-18 08:01:47 pm

tugboat666
Member
From:: Marysville, OH
Registered: 2003-01-21
Posts: 92

Re: How to get results from do shell script

I don't remember if it was on this board or on the Apple/Applescript board, but I remember a discussion about this. When 'do shell script' is called, a shell is opened (I think /bin/sh) neither .login, .tcshrc nor .cshrc are read, therfore environment variables will not be defined for the do shell script.

Not sure what a workaround would be ...

Offline

 

#9 2003-08-18 08:26:06 pm

obedortiz
Member
Registered: 2003-02-12
Posts: 7

Re: How to get results from do shell script

Thanks for your help. That clarifies it. It is just not possible to interact with an application that way. I would have to keep the terminal open and pass commands to it but still might now be able to get the response. The other option would be to use expect and learn tcl which defeats the purpose of applescript.

Thanks all!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)