[Solved] Running shell code in AppleScript without Terminal

What I want my script to do is to run a command in Terminal and close that same Terminal window when the process is complete.

Of course I could ad a delay of 6 seconds to complete the process, but it may not be enough every time.

To simplify my question, this is what I want to achieve.

  1. Quit Terminal after process completes.
  2. Quit "that" Terminal window, not all active Terminal windows.

Thank you

(I didn't exactly knew where to put this topic, so I placed it in here, on second thought it would have been better to put it into "Shell Programming and Scripting" Which I did and got locked. Excuse me for this)

While I brush up (i.e. learn some) AppleScript, a quick work-around

osascript << !
activate application "Terminal"
tell application "System Events" to keystroke "command; exit\r"
!

It wouldn't really be better to put it in the Shell Scripting forum, as this is "an Apple thing"!

Thank you scottn, I will try that.

I'm quite new to UNIX, I need to learn the basics.
When I read Shell scripting, I immediately thought of AppleScript.

I want to learn scripting and programming in OS X, so I need to a little help from time.

And I'm very new to AppleScript.

It seems to run that "tell" stuff asynchronously, and I was trying to work out how to not do that, so until I do, or someone else chips in with a better solution, I'm a student just like yourself :slight_smile:

If you want to run those commands without a visible terminal, running /bin/sh instead of Terminal should provide the same result.

@Scottn

Thank you for your help, I appreciate it.
If will try to help wherever I can, too.

@Corona688

Good call, I once stumbled into that searching google, but AppleScript gave me a Syntax error ( / )

Could you give me a example of how to use it properly?
Thanks in advance.

Applescript apparently has an even more direct way to do this: "do shell script". No need to fake keystrokes to anything at all.

do shell script "command"

I don't think that will need an exit after it.

Thank you Corona688, that worked like a charm! :smiley:

Yep. Changed the subject title to more accurately reflect the solution, and marked as solved :smiley:

Thanks for the correction, I hope others find it useful as well. :slight_smile: