• 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: osascript from the terminal: error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: osascript from the terminal: error?


  • Subject: Re: osascript from the terminal: error?
  • From: John W Baxter <email@hidden>
  • Date: Fri, 30 Mar 2001 07:51:03 -0800

At 20:40 +1000 3/30/01, Timothy Bates wrote:
>hi there,
>just playing with osascript from the terminal, and I get errors
>
>[localhost:~] tim% /usr/bin/osascript 2 + 2
>Syntax error: Expected expression but found end of script. (-2741)
>
>Of course 2+2 is a perfectly valid script. Any ideas on these errors?
>(man osascript does not define them)
>
>Also, I can execute this without error
>
>
>[localhost:~] tim% /usr/bin/osascript beep
>
>but I hear nothing (I do hear the beep in script debugger (which is so far
>flawless in classic box), so it is not the no sound in X bug).

man osascript is your friend.

It reveals that what is on the command line is the name of a file
containing your script...if omitted then standard input (you and your
keyboard, often) is compiled. [Note that end of file is command D, and
unfortunately the D gets echoed, as in
[localhost:~] john% /usr/bin/osascript
return 2+2
4D

The man page's Bugs section reveals that you must type the full path to
osascript...using just osascript above yields the amusing but useless and
somewhat circular
[localhost:~] john% osascript
return 2+2
Syntax error -1750. Couldn't get error text because of error -1750.

To get rid of the D, one can inject the one-line script via echo:
[localhost:~] john% echo "return 2 + 2" | /usr/bin/osascript
4
[localhost:~] john%

(for that script, the quotes aren't needed...for 2 * 2 they are:

[localhost:~] john% echo return 2 * 2 | /usr/bin/osascript
Syntax error: A plural class name can't go after this number. (-2740)

so it's easier to use the quotes all the time. (Here, the shell has
expanded * to all the file names in the current directory.) [Don't even
think about using &.] If it gets hard to write the echo, just make a
temporary file

[localhost:~] john% cat /tmp/script
set x to 2 * 2
return x
[localhost:~] john% /usr/bin/osascript /tmp/script
4

--John (who hasn't used this for anything worthwhile yet)

--
John Baxter email@hidden Port Ludlow, WA, USA


References: 
 >osascript from the terminal: error? (From: Timothy Bates <email@hidden>)

  • Prev by Date: Re: osascript from the terminal: error?
  • Next by Date: Re: osascript from the terminal: error?
  • Previous by thread: Re: osascript from the terminal: error?
  • Next by thread: Re: osascript from the terminal: error?
  • Index(es):
    • Date
    • Thread