Re: Scripting the Location
Re: Scripting the Location
- Subject: Re: Scripting the Location
- From: Craig Sutherland <email@hidden>
- Date: Sat, 30 Aug 2003 20:47:45 -0500
Paul,
In the tcsh shell you can't redirect stdout and stderr separately, but
you can make stderr go into the same file as stdout. In a bash shell
they can be directed separately. So it depends on whether it is a
script, which uses bash, or the interactive tcsh shell in Terminal at
work.
Craig
On Saturday, August 30, 2003, at 06:56 PM, Paul Berkowitz wrote:
Thanks, John. that's just what I needed to know. I'd seen discussions
of "
2>&1 " here before and thought that might be the way, but I couldn't
recall
exactly how it worked. Nor did I understand why this might be an error.
A follow-up: why does the Terminal not see it as an error? Does tcsh
simply
receive stderr as well as (instead of) stdout without murmur, while
AppleScript's sh/bash receives only stdout?
--
Paul Berkowitz
--John (Testing Entourage for mailing lists after years of using
Eudora)
[Make sure you check out the Mailing List Manager (Tools menu). On the
Options tab, you can set this list (and others like it) to override the
list's preferences to always reply to the list, so you never have to
remember to do that (nor to Reply to All as a shortcut which may annoy
the
person you're replying to). And do take the offer to add the list to
your
Address Book when you save, so list messages will never get marked as
Junk
even when you have a high setting for the Junk filter.]
From: "John W. Baxter" <email@hidden>
Date: Sat, 30 Aug 2003 15:50:19 -0700
To: AppleScript-Users <email@hidden>
Subject: Re: Scripting the Location
On 8/30/2003 13:05, "Paul Berkowitz" <email@hidden> wrote:
On 8/30/03 12:41 PM, "John C. Welch" <email@hidden> wrote:
On 08/30/2003 15:17, "Paul Berkowitz" <email@hidden> wrote:
When I do it from 'do shell script' (OS 10.2.6), I get it as part
of an
error message instead of directly:
do shell script "scselect"
ERROR --> "usage: scselect [-n] new-set-name
Defined sets include: (* == current set)
0 (Home)
* 1 (Modem On)
2 (File Sharing)"
What is the [-n] new-set-name all about? There is no 'man
scselect' nor
'apropos scselect', and nothing in my 1100-page "Unix Power Tools"
about it
either.
Without any number after scselect, you get the current selection
out of all
the configs. If you wanted to change to your Home setting, you
would use
scselect 0
I'm fully aware of that from your last message, thanks. That wasn't
the
question. What I'm trying to do is get the list of all locations,
and the
current location (the one with the * ) in a reliable way, not to set
the
location. My result for scselect in the Terminal included a line
yours
didn't (or perhaps you excised it?):
"usage: scselect [-n] new-set-name
"
and when I did
do shell script "scselect"
in AppleScript, I got all this stuff as an ERROR, not as a result. I
thought
I spelled this out in the last message, no? Try it yourself in
AppleScript.
Do you get an error, or do you get a result.
Actually there were two questions:
1. Why am I getting an ERROR in AppleScript?
You are getting an error because the scselect command can only be
called
with one parameter (plus an optional -n).
Since the command was called incorrectly, it puts out its usage
error, which
happens to contain the information you want.
Try
do shell script "scselect 2>&1 | cat"
Error messages come out on stderr, (file 2) not stdout (file 1). So
we do
the very ugly 2>&1, which sends stderr into the stdout text stream.
Why pipe the output through cat? The scselect returned an error code
of 1.
Do shell script picks up the non-zero error code. By piping the
output
through cat, we get rid of the error code (there are other ways*).
You could do this if you only want the current location line:
do shell script "scselect 2>&1 | grep '*' | grep -v Defined"
(there are other ways to do that, too).
From the above, I get
" * 10 (Linsys--fixed)"
(I've had this location for several years, and never noticed I left
the 'k'
out of Linksys.)
2. And is there any way to avoid it other than the try/error block I
used?
The error number is 1 (yup, 1) so I can trap for that number
particularly,
but I'd bet there's something more reliable I can do in the shell
script to
avoid the error.
Aside from the discussion above, here's another way to evade the
error:
do shell script "scselect 2>&1 | tee /dev/null"
(tee sends its input to the designated file AND to its output...we
throw
away the file output.)
--John (Testing Entourage for mailing lists after years of using
Eudora)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
C-
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.