• 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: Command line args in MacOS X
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Command line args in MacOS X


  • Subject: Re: Command line args in MacOS X
  • From: Christopher Nebel <email@hidden>
  • Date: Mon, 23 Apr 2001 12:29:39 -0700

On Saturday, April 21, 2001, at 10:22 AM, email@hidden wrote:

I can't imagine this question not coming up before but I can't find
it in the archives.

From Mac OS X I want to execute an applescript from the Terminal
command line and have any command line arguments available
to the script.

This isn't directly supported, but you can fake it using a wrapper command. I'm guessing you've already discovered osascript, which lets you execute a script, but won't pass additional parameters through to the script. (If you haven't, check out "man osascript".) The basic technique is to write a small wrapper command that takes your script, tacks the parameters onto the front as a property definition, and then executes the result. Here's one way to do it:

#!/bin/sh
# Usage: osascriptargs scriptfile [arguments]
S=$1
shift
echo property arguments: \""$@"\" | cat - $S | /usr/bin/osascript

A more advanced version would pass in the arguments as a list, not a string, so it would preserve multi-word arguments, wouldn't require a script file, and would let you pass options to osascript itself. That's a little more than I'm willing to do in sh on a Monday morning, though. At some point, I'd like to provide real support for this sort of thing osascript, but that's a ways off.


--Chris Nebel
AppleScript Engineering

P.S.: A similar stunt will let your script process stdin. For example, the following will take stdin, lump it all into an "input" property and stick it onto the specified script:

#/bin/sh
sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' \
-e '1s/^/property input : "/' \
-e '$s/$/"/' | \
cat - "$@" | /usr/bin/osascript

Combining this with the arguments hack is left as an exercise for the reader.


  • Prev by Date: off subject...but help is needed....
  • Next by Date: UPPER Command
  • Previous by thread: Re: Command line args in MacOS X
  • Next by thread: Re: Command line args in MacOS X
  • Index(es):
    • Date
    • Thread