Re: Changes in osascript?
Re: Changes in osascript?
- Subject: Re: Changes in osascript?
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 27 Jan 2009 23:10:57 -0500
It looks like that awk command is incorrect. OMM, the fourth field of
"ps -c -U $USER" is not the application, it's the timestamp. Perhaps
the script originally worked on an older version of OS X with a
different ps output format? Even $5 will not necessarily be exactly
equal to "Mail", though; it could be "/Applications/Mail.app", for
instance. I seem to recall a thread on determining if an application
is running from Applescript without launching it, which might be a
cleaner solution here. Below I just use a less picky test via grep.
Also, what gets run from cron is interpreted as a shell script
already; having that shell script use osascript to run shell commands
via "do shell script" is a little roundabout. I would either do the
shell stuff directly from the cron script and only call osascript for
the part that talks to Mail, or go the other way and make the whole
thing an osascript script by replacing the #!/bin/sh with
#!/usr/bin/osascript (although that won't work on older systems).
Here's one possible replacement:
#!/bin/sh
if ps -c -U"$USER" | grep Mail | grep -qv grep; then
osascript -e 'tell application "Mail" to set content of signature
"Fortune" to do shell script "/opt/local/bin/fortune
/Users/syth/mysigs" '
fi
(I'm using a small dab of the solution I just called "roundabout" -
osascript -e '... do shell script' - to avoid the quoting issues that
would arise from calling fortune from the shell first and then trying
to pass its output into osascript on the command line.)
I also suspect that there could be a better way to do dynamic sigs
from within Mail.app, but I don't know what that way might be.
On Tue, Jan 27, 2009 at 9:28 PM, LuKreme <email@hidden> wrote:
> I have the following script which I have been using via cron for along time
> (Since I posted about it in Apr 08). It stopped working recently, so I
> decided to make a LaunchAgent for it, but it still does not work. The
> script is run, but the script cannot see that Mail is running:
>
> #!/bin/sh
> /usr/bin/osascript \
> -e "set myname to system attribute \"USER\"" \
> -e "set shellscpt to \"ps -c -U \" & myname & \" | awk '/Mail/{print
> \$4}'\""\
> -e "set myMail to do shell script \"echo\" & space & (quoted form of
> shellscpt) & space & \"| /bin/bash\" " \
> -e "if myMail = \"Mail\" then "\
> -e " set fortune to do shell script \"/opt/local/bin/fortune
> /Users/syth/mysigs\""\
> -e " tell application \"Mail\" to set content of signature \"Fortune\" to
> \"-- \" & return & fortune"\
> -e "end if"
>
> touch $HOME/.sigrun
>
> I know the script is getting run, because .sigrun is updated with the
> appropriate time stamp. I did some debugging (not that I understood it) and
> posted it at <http://home.kreme.com/randsig-debug.txt>
>
> Running the script (~/bin/randsig) manually works fine; running the ps
> command does exactly what is expected:
>
> $ ps -c -U kreme | awk '/Mail/{print $4}'
> Mail
>
>
> the cron failure email message also contains these headers:
>
> X-Cron-Env: <SHELL=/bin/sh>
> X-Cron-Env: <PATH=/usr/bin:/bin>
> X-Cron-Env: <LOGNAME=kreme>
> X-Cron-Env: <USER=kreme>
> X-Cron-Env: <HOME=/Users/kreme>
>
> I went ahead and added the full path to osascript anyway, but no change.
>
>
> It appears to me that the script no longer is able to see that Mail.app is
> running, but ps and awk are in the path (/bin/ps /usr/bin/awk).
>
>
> --
> I loved you when our love was blessed I love you now there's
> nothing left But sorrow and a sense of overtime
>
> _______________________________________________
> 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
>
--
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