0

so I'm totally new to applescript..

basically I want my applescript.app to run a shell script then exit

do shell script "/usr/local/groovy/bin/groovyConsole"

the above script opens groovyConsole just fine, but my applescript.app is still running - I want it to close itself after it runs the shell script....

any help would be great!

zack
  • 101
  • 1
  • 2

2 Answers2

2

You can have the shell run a program “in the background” (by appending &), but do shell script will still wait until every process has closed any instances of the file descriptors it opened for the program’s stdout and stderr. Redirecting them will suffice.

do shell script "/usr/local/groovy/bin/groovyConsole >/dev/null 2>&1 &"
Chris Johnsen
  • 39,401
  • 6
  • 111
  • 111
  • I'm not sure output redirection is necessary -- [sometimes](http://superuser.com/questions/16750/how-can-i-run-an-application-with-command-line-arguments-in-mac-os/236446#236446) it works without. – Daniel Beck Mar 12 '11 at 09:38
  • @Daniel: It is required for the general case. It is not required for your specific example because *open* (actually LaunchServices) does the work of “backgrounding” and making sure the stdout and stderr of the processes it ultimately leaves running are sent elsewhere (to the per-user *launchd* in 10.6). – Chris Johnsen Mar 13 '11 at 02:57
  • I was referring to my first snippet, calling the binary directly. `open` is very different, true. I just don't see what's wrong with Trevor's answer. – Daniel Beck Mar 13 '11 at 05:16
  • 1
    @Daniel: Your first snippet uses Automator; its *Run Shell Script* does not do the same “wait for all instances of stdout/stderr pipes to close” thing that AppleScript’s *do shell script* does. Example: `do shell script "sleep 5 &"` always takes 5 seconds to return, but `do shell script "sleep 5 >/dev/null 2>&1 &"` always returns as quickly as possible. The shell exits and *sleep* runs in the background in both cases; however, in the first case, *sleep* has inherited the fds against which *do shell script* is waiting. Trevor’s answer may work, but it depends on the behavior of *groovyConsole*. – Chris Johnsen Mar 13 '11 at 06:17
  • That's good to know. Thanks for the clarification! – Daniel Beck Mar 13 '11 at 06:19
0

Just a thought, try adding an ampersand sign to the end of the script.

do shell script "/usr/local/groovy/bin/groovyConsole &"

It backgrounds the commands and will return you to a prompt (when at a command line). It might just make the Applescript app finish.

Good luck!

Trevor
  • 133
  • 1
  • 6