[Solved] Running shell code in AppleScript without Terminal

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) [Solved] Running shell code in AppleScript without Terminal
# 1  
Old 06-30-2011
Question [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.

Quote:
activate application "Terminal"
tell application "System Events" to keystroke "command"
tell application "System Events" to keystroke return
tell application "Terminal"
quit
end tell
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)

Last edited by ShadowofLight; 06-30-2011 at 04:21 PM..
# 2  
Old 06-30-2011
While I brush up (i.e. learn some) AppleScript, a quick work-around

Code:
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"!
# 3  
Old 06-30-2011
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.
# 4  
Old 06-30-2011
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 Smilie
# 5  
Old 06-30-2011
If you want to run those commands without a visible terminal, running /bin/sh instead of Terminal should provide the same result.
# 6  
Old 06-30-2011
@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.
# 7  
Old 06-30-2011
Applescript apparently has an even more direct way to do this: "do shell script". No need to fake keystrokes to anything at all.

Code:
do shell script "command"

I don't think that will need an exit after it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running q-shell commands( on IBM-i Series) from cygwin terminal (on windows)

I have cygwin installed on windows server and when I do echo $SHELL the output is /bin/bash I have created a ssh tunnel from this windows server through cygwin to ibm -i series which is running Q-shell. I am trying to invoke a utility wsadmin (used for scripting) on ibm-i from the... (12 Replies)
Discussion started by: gaurav99
12 Replies

2. AIX

[Solved] Find command hangs my terminal session

Hello every one. I know little to nothing about AIX. Recently I have been assigned to an AIX project. For some reason or another the find command is hanging the server. Well it does not hand server per say, it just freezes my terminal session. after running find, I waited up to 40 min and... (3 Replies)
Discussion started by: busi386
3 Replies

3. Shell Programming and Scripting

[Solved] Running a R script with in a shell script

Hi, I do have an R script named KO.R. Basically reads thousands of files, whose name has a pattern that differs at a portion of the file name, List.txt. Row_file1_mile.txt Row_file2_mile.txt Row_file3_mile.txt ... ... Row_file1000_mile.txt Below is a portion of my Rscript that reads... (4 Replies)
Discussion started by: Kanja
4 Replies

4. Shell Programming and Scripting

[Solved] Shell not running through cron

Hi freinds, I have tried running a script through cron ,it is a shell script which calls a oracle procedure , problem here is that there is function in sql code which makes a external C call , this function is failing when running manually but works when run manually. I have trouble shooted... (6 Replies)
Discussion started by: Jcpratap
6 Replies

5. Shell Programming and Scripting

SED command works in terminal, but not Applescript

The following command works perfectly in Terminal, but not in Applescript. (Returns "unknown token" error for square brackets.) (new to site. sorry.) I have an Applescript that is designed to find and remove any square-bracketed text, including the square brackets. I ran the following code from... (1 Reply)
Discussion started by: Phillip Acosta
1 Replies

6. Shell Programming and Scripting

Running shell script in Cygwin terminal

I am new to shell scripting. I tried to run a simple shell script using Cygwin terminal in Win XP env. The script I have written is as follows - #!/bin/bash a=5 ] && echo "true" || echo "false" But when I execute the script, getting some confusing error. The error I am getting are - ... (3 Replies)
Discussion started by: linux_learner
3 Replies

7. OS X (Apple)

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In the... (2 Replies)
Discussion started by: JFraser1
2 Replies

8. Shell Programming and Scripting

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In... (3 Replies)
Discussion started by: JFraser1
3 Replies

9. Shell Programming and Scripting

Terminal vs. Applescript

I am running Mac OS X (10.5). I run the following script successfully in terminal in order to split an mp3 file into 3 smaller mp3 files... split -b 8667k -a1 Monday.mp3 Levin-Hour_; ls Lev* | sed "s/.*/mv '&' '&.mp3'/g" | zsh However, when I run a similar script within the Applescript editor... (2 Replies)
Discussion started by: tgaleza
2 Replies

10. UNIX for Dummies Questions & Answers

check my code?? running shell from c?

Hi mates, i am trying to run a shell command from my C program in this case let is say the "ls" command. It copiles it okay, and even creates the new fork too. But seems to nothing is happening i mean it is not showing the result of the "ls" command. I don't know wat i am doing wrong. Any... (1 Reply)
Discussion started by: abdul
1 Replies
Login or Register to Ask a Question