• 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: using a shell variable in an osascript line?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using a shell variable in an osascript line?


  • Subject: Re: using a shell variable in an osascript line?
  • From: LuKreme <email@hidden>
  • Date: Sat, 28 Feb 2009 13:31:08 -0700

On 27-Feb-2009, at 18:32, Axel Luttgens wrote:
Could you give us a full (yet simplified) example of the kind of workflow you are considering?


Sure, without getting into too many specifics.

Basically I have a shells script that grabs some piece of transient data, perhaps like I said from a log file, or a grep | tail -1 of a rapidly changing file.

It then uses this line in some way, perhaps sending it in an email or writing it to a file or extracting the pid ... whatever.

Now, I want to sent the value of the variable to an application like BBEdit

tell application "BBEdit"
replace (mySearch as string) using ("$VAR1" as string) options {search mode:literal, starting at top:true} searching in text 1 of text window 1
end tell


(wrap that all in an osascript -e)

you know what, I can adapt my old rand signature applescript to this process and show it in a complete script:

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


It's a bit silly in this case as it is trivial to get another 'fortune' and there is no reason for the Fortune signature and the .signature to be synced, but there you have it.

Actually, it's a good example because the fortune file contains all sorts of characters. For example, in my method I can already see that the line wrapping gets munged.

"...when you're no longer searching for beauty or love, just some
	kind of life with the edges taken off. When you can't even
	define what it is that you're frightened of..."

becomes:

"..when you're no longer searching for beauty or love, just some kind of life with the edges taken off. When you can't even define what it is that you're frightened of..."

This does not happen if I set the content of the signature this way

"tell application \"Mail\" to set content of signature \"Fortune\" to \"-- \" & return & (do shell script \"/opt/local/bin/fortune $HOME/ mysigs\")"

--
"Why do you wear that stupid bunny suit?" "Why are you wearing that stupid man suit?"


_______________________________________________
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
References: 
 >using a shell variable in an osascript line? (From: LuKreme <email@hidden>)
 >Re: using a shell variable in an osascript line? (From: Axel Luttgens <email@hidden>)
 >Re: using a shell variable in an osascript line? (From: LuKreme <email@hidden>)
 >Re: using a shell variable in an osascript line? (From: Axel Luttgens <email@hidden>)

  • Prev by Date: Sturm, Lewis is out of the office.
  • Previous by thread: Re: using a shell variable in an osascript line?
  • Next by thread: Re: using a shell variable in an osascript line?
  • Index(es):
    • Date
    • Thread