Re: using a shell variable in an osascript line?
Re: using a shell variable in an osascript line?
- Subject: Re: using a shell variable in an osascript line?
- From: "Mark J. Reed" <email@hidden>
- Date: Sun, 1 Mar 2009 15:34:05 -0500
You misunderstand. "do shell script" is fine, but "do shell script"
within an applescript that's BEING RUN FROM OSASCRIPT is what I called
silly. :) It's already a shell script, just do the shell stuff in the
shell env.
And yes, we covered on run(argv), but then, *after* that, you
indicated you were still having trouble making it work. So I thought
I would take your complete-script example and translate it into
another complete-script example to demonstrate. Sorry if it was
superfluous.
"If [ ]" is apparently ok in bash; other versions of sh fail on it.
On 3/1/09, LuKreme <email@hidden> wrote:
> On 1-Mar-2009, at 09:29, Mark J. Reed wrote:
>> On Sat, Feb 28, 2009 at 3:31 PM, LuKreme <email@hidden> wrote:
>>> #!/bin/sh
>>>
>>> # Is the current user running Mail?
>>> MAIL=`ps -U"$USER" -co command | grep Mail`
>>>
>>> #Get a random 'fortune' for signature
>>> RAND=`/opt/local/bin/fortune /path/to/mysigs`
>>>
>>> #write the fortune to .signature for slrn, Postbox, and
>>> Thunderbird's use
>>> echo $RAND > $HOME/.signature
>>>
>>> if [ $MAIL ]; then
>>> osascript -e "set myVAR1 to (do shell script \"cat
>>> $HOME/.signature\") as text" \
>>> -e "tell application \"Mail\" to set content of signature
>>> \"Fortune\" to \"-- \" & return & myVAR1"
>>>
>>
>> OK, osascript -e 'do shell script' is patently silly.
>
> No, do shell script is often required in an Applescript. "do shell
> script (\"cat…" is silly, I'll grant you. But then this was posted
> as an example and not as a suggested script to use. The point of all
> this is the passing of a variable from the shell script portion into
> an osascript cleanly. I think we decided that passing the argv was the
> way to go, though I've not actually checked if the the text is
> preserved exactly (including spacing, tabs, CRLFs, etc).
>
>>> if [ $MAIL ]
>>
>> is going to be a syntax error if Mail isn't running,
>
> Nope, no syntax error. That particular statement has been working
> just fine for a long time. if Mail.app is running, then the block
> executes and if Mail.app is not running, it doesn't. No error (not on
> the command-line, not in console, not anywhere).
>
> try this:
> $ if [ ]; then echo "yes"; else echo "no"; fi
> no
> $ if [ "" ]; then echo "yes"; else echo "no"; fi
> no
> $ if [ "anything" ]; then echo "yes"; else echo "no"; fi
> yes
>
> Now, on the other hand, "if $MAIL ..." *does* generate a syntax error
> if Mail.app is not running.
>
>> on run(argv)
>
> Yep, we already covered the use of on run(argv) didn't we?
>
> --
> Like the moment when the brakes lock/And you slide towards the big
> truck/You stretch the frozen moments with your fear
>
> _______________________________________________
> 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
>
--
Sent from my mobile device
Mark J. Reed <email@hidden>
_______________________________________________
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