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: LuKreme <email@hidden>
- Date: Sun, 1 Mar 2009 12:06:52 -0700
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