Re: Scripting the Location
Re: Scripting the Location
- Subject: Re: Scripting the Location
- From: "John W. Baxter" <email@hidden>
- Date: Sat, 30 Aug 2003 15:50:19 -0700
- Envelope-to: email@hidden
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.