3

I have a shell script that runs an applescript. The applescript is executed from a terminal and I want that terminal to close after its done.

In my shell script I execute my applescript with this line. It opens a terminal, runs and then the terminal just sits there even though the applescript is done. I have other terminals open that I use all the time so I don't want to close all of them, just that one.

 osascript -e 'Tell application "Terminal" to do script "osascript ~/Scripts/reset_simulator.applescript"' 

Thanks

2 Answers 2

4

In your shell script, you executing the

osascript -e 'Tell application "Terminal" to do script "osascript ~/Scripts/reset_simulator.applescript"' 

what really opens an new Terminal.app window.

Have you some special reason to open an new terminal window? Why just not running the

osascript ~/Scripts/reset_simulator.applescript 

from your shell script and in the current window.

But if you want such thing (sounds to me strange) always can use the next:

osascript -e 'Tell application "Terminal" to do script "osascript ~/Scripts/reset_simulator.applescript;exit"' #note the "exit" here ---------------------------------------------------------------------------------^^^^^ 

and change the Preferences to "close window" when the shell exits.

Reading your comments above, sounds me than you want run some applescript in the "background".

So you can do the next:

a.) from your shell script

osascript ~/Scripts/reset_simulator.applescript & 

2.) if you want still open the another terminal window

osascript -e 'Tell application "Terminal" to do script "osascript ~/Scripts/reset_simulator.applescript&exit"' #note the & here --------------------------------------------------------------------------------------^ 
Sign up to request clarification or add additional context in comments.

5 Comments

I tried running it without the terminal like you suggested, but this shell script is being called from a TeamCity buildagent and there is some sort of privacy/security issue that doesn't let the applescript run.
@deluded12ga - so, i added another option (see the exit). But understand, than the exit will be executed only when the reset_simulator.applescript finished, as @nneonneo said in the comments above.
enjoy, happy to helping.
Curious though, whats the & do on option a.)
@deluded12ga The & in shell it sends the command into the "background", so the execution of the "foreground" script continues immediatelly with the next command. Usually, the background jobs geting stopped when the shell exits, but probably your script is handling such signals.
1

In your Terminal settings, change the setting under "Shell->When the shell exits" to "Close if the shell exited cleanly".

Settings

4 Comments

That doesn't work, tried it. The terminal stays open.
Does it say "[Process completed]" at the end of the open window?
once the script runs, it says "menu item Quit iOS Simulator of menu iOS Simulator of menu bar item iOS Simulator of menu bar 1 of application process iPhone Simulator"
How do I got about telling an applescript to exit after its done?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.