Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

so I'm totally new to applescript..

basically I want my to run a shell script then exit

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

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

any help would be great!

share|improve this question

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 &"
share|improve this answer
I'm not sure output redirection is necessary -- sometimes it works without. – Daniel Beck Mar 12 '11 at 9: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 2: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 5:16
@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 6:17
That's good to know. Thanks for the clarification! – Daniel Beck Mar 13 '11 at 6:19

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!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .