Re: Calling shell script, returning results.
Re: Calling shell script, returning results.
- Subject: Re: Calling shell script, returning results.
- From: Doug McNutt <email@hidden>
- Date: Fri, 19 Dec 2008 08:52:29 -0700
At 17:06 -0800 12/18/08, Chris Page wrote:
On Dec 18, 2008, at 10:04 AM, Michele (Mike) Hjorleifsson wrote:
If you call a shell script from applescript is there a way to capture
the resultant output from the shell script so you could present it
nicely in the GUI for the user ?
As Steve Hayman mentioned, the result of the 'do shell script'
command contains whatever is written to standard out.
In order to help me understand whether the documentation needs
improvement, I'd like to ask whether you looked at the Standard
Additions terminology dictionary entry for 'do shell script' and
whether you were unable to find your answer there:
do shell script v : Execute a shell script or command using the 'sh' shell
do shell script text : the command or shell script to execute.
Examples are 'ls' or '/bin/ps -auxwww'
[as type class] : the desired type of result; default is text (UTF-8)
[administrator privileges boolean] : execute the command as the administrator
[user name text] : use this administrator account to avoid a password
dialog (If this parameter is specified, the "password" parameter must
also be specified.)
[password text] : use this administrator password to avoid a password dialog
[altering line endings boolean] : change all line endings to
Mac-style and trim a trailing one (default true)
Æ text : the command output
For answers to commonly asked questions about do shell script,
see <http://developer.apple.com/technotes/tn2002/tn2065.html>Technical
Note TN2065.
I'm not exactly a neophyte but I was once terribly confused by that
block of information that pretends to be a man page. In particular:
do shell script v -- Just what is that v for? Is it, perhaps, short
for a file name or alias that is a vector to a script file?
do shell script text -- Is that a correction to the line above which
contained a typo? Is the AppleScript command do_shell_script_text ?
Or do I type do_shell_script and follow it with the text that is the
shell command I want to execute. A shell script is something prepared
in advance that is typically stored in a file and sometimes has a #!
line. Is such a file sourced or exec'd by sh? A command is some text
that fits on a line and makes sense to the shell. If passing a file
reference should it be an alias, a POSIX path, or something else?
( As an aside. . . can do_shell_script send commands to a pipe or
fifo? I know how to make a shell daemon that behaves as a persistent
shell and remembers its environment between requests, It's working
on ubuntu. )
[as type class] -- I was pretty sure I know what a type was. Int,
float, double, char came immediately to mind. But the result comes
back as type "class". What is that all about? Can I say
do_shell_script echo 3 as int? I doubt it. This neophyte has read
about object oriented coding and thinks a class ought to have methods
that were once called subroutines but "class text" doesn't seem to
fit that model and neither does type text.
Why would anyone want to trim a trailing digit 1? Result of -- echo
"Hello world \n\n\n" ?
(If this parameter, administrator, is specified, the "password"
parameter must also be specified.) -- That's just not consistent with
"to avoid a dialog" in the password line. It seems that the whole
idea is that the shell can be executed with a username other than the
login. Just defining setuid might be easier on the novice.
Finally, the thing that is needed most in the dictionary presentation
is not even there. Without the Chris # 1 technote a neophyte would
never get a script to run. Quoted_form_of is almost always required.
The dictionary ought to indicate that the shell is executed without
benefit of any environment variables, including $PATH, that you might
have set up with a .profile or .cshrc file and it ought to suggest
that $HOME/.MacOSX/environment.plist is a option. It ought also to
warn that a new process is begun for each do_shell_script in an
AppleScript. You cannot set a working directory and expect it to be
there when you return.
Some examples of actual AppleScript text illustrating each of the
options would really be valuable as a part of the presentation of the
dictionary. A Script Editor option to paste an example in the current
editing window when a dictionary item is option_clicked would be
Apple-like. Displaying the actual AppleEvent codes would also be
useful.
--
--> From the U S of A, the only socialist country that refuses to admit it. <--
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden