• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Changes in osascript?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changes in osascript?


  • Subject: Re: Changes in osascript?
  • From: LuKreme <email@hidden>
  • Date: Wed, 28 Jan 2009 07:10:05 -0700

On 27-Jan-2009, at 23:13, Scott Babcock wrote:
Whenever I include 'ps' as part of a scripting task, I always limit its output to the fields I actually need through the '-o' option. In this case, it appears that all you really want is the command:

ps -U "$USER" -co command

I'd still need an awk or grep

This way, you don't need to deal with as many version-to-version formatting issues.
________________________________
Date: Tue, 27 Jan 2009 23:10:57 -0500
From: "Mark J. Reed" <email@hidden>

I never saw Mark's reply... :/

Subject: Re: Changes in osascript?
To: LuKreme <email@hidden>
Cc: applescript <email@hidden>
Message-ID:
       <email@hidden>
Content-Type: text/plain; charset=UTF-8

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.

Not here. As I said, the script works perfectly -- If I run it manually.


ps -c -U $USER outputs lines like:

 1602 ??         0:20.57 DashboardClient
 2856 ??       126:05.82 VLC
 4500 ??        25:42.84 Mail
 4791 ??         0:16.56 TextEdit
 5475 ??         4:08.63 Backup

As you can see the 4th field is the command. And it's been running since April of last year.

#!/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

That seems to work, though I went ahead with the short output for ps (and avoided the grep -v)


if ps -U"$USER" -co command | grep Mail; then
osascript -e 'tell application "Mail" to set content of signature "Fortune" to \
"-- " & return & (do shell script "/opt/local/bin/fortune /Users/ syth/mysigs")'
fi


The only problem I see with this is that the if conditional generates "Mail" when run from the command line. I've reënabled it as a LaunchAgent and I get

28-Jan-09 06:52:28 com.kreme.home.randsig[9845] Mail

In the Console ever time it fires. Small price to pay, perhaps, though I'd prefer to eliminate it.

Maybe:

MYMAIL=`ps -U"$USER" -co command | grep Mail`
if $MYMAIL ; then
osascript -e 'tell application "Mail" to set content of signature "Fortune" to "-- " & return & (do shell script "/opt/local/bin/ fortune /Users/syth/mysigs")'
fi


...

But when I run that from the CLI I get "No Mail for $USER" as a result, and logged to Console twice, so I'm not rally gaining anything there. In fact, I'm losing since I now have two lines output to the Console. OTOH, I can ignore the Console... :P

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.

Yeah, if you think of anything, lemme know :)

Thanks for the help though, I now have Random Sigs again, based on my plain-text fortune-file. Huzzah!

--
Do not meddle in the affairs of Dragons for you are crunchy and
	taste good with ketchup

_______________________________________________
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
  • Follow-Ups:
    • Re: Changes in osascript?
      • From: "Mark J. Reed" <email@hidden>
References: 
 >RE: Changes in osascript? (From: Scott Babcock <email@hidden>)

  • Prev by Date: Re: How do I create a Applescript Interface for my Application
  • Next by Date: Re: Changes in osascript?
  • Previous by thread: RE: Changes in osascript?
  • Next by thread: Re: Changes in osascript?
  • Index(es):
    • Date
    • Thread