How to do 'shell' functions in OS X
Mac OS X Only (Mac OS X Only)

On Friday, March 22, 2002, at 04:42 PM, Dar Scott wrote:

> The dictionary on my Revolution has OS X crossed out for "shell"
> and "read from process", but curiously not for "open process".

I guess the AppleScript programmers on the list laugh every time I say there is no Revolution shell() function that works on OS X.

I know nothing about AppleScript, but with a tiny bit of fooling around I came up with this:

function shellSH cmd
  -- Sorry, no quote marks in cmd in this version
  -- And shellCommand is ignored
  put "do shell script" & quote & cmd & quote into s
  do s as AppleScript
  put result() into r
  replace numToChar(13) with linefeed in r
  return r
end shellSH
This uses sh and not tcsh that the Terminal program uses. There is probably a way to do this with Terminal, but even those six lines of AppleScript are beyond me until I get a reference.

Here is one way to ping, then:

function ping ip
  return shellSH("/sbin/ping -c 1 " & ip) contains "1 packets received"
end ping
This takes over 10 seconds if the computer is not there. It returns virtually immediately if it is. I tried -w, but it doesn't seem to work.

I still hear giggling.

Posted 3/22/2002 by Dar Scott to the Use-Revolution List   (See the complete post/thread)