I wrote an .command script that when I launch it, it just exits and it's to quick for me to see what's going on. How do I keep it open?


When you double click a .command in the Finder, the Terminal opens and runs /path/to/your.command ; exit; The exit at the end exits the shell, and you have Terminal's preferences set to close the window when this happens.

  • Go to Terminal -> Preferences -> Settings -> Whichever Theme is marked as the Default -> Shell -> When the shell exits: and choose "Don't close the window".

Alternatively, if you don't want to change Terminal's preferences:

  • If your command outputs something to STDOUT that you want to read after the command exits, you can pipe the command's output through less, which will then stay open allowing you to scroll around through the output with the arrow keys until you quit it with q. Just add |less to the end of the command in your script.


  • Found a more flexible option. If piping something through less isn't practical for whatever reason, or your script is too complicated, you can add a last command that waits for input from the user before completing. I used
$ read -n 1 -p "Done. Press any key to exit. "

(Wait for one character of input while displaying the prompt.)

|improve this answer|||||
  • Thanks! I thought about piping the command but the issue is that the command works fine if I run it from command line, but it doesn't when I open it through finder for whatever reason. – Kit Sunde Feb 13 '12 at 8:24
  • 1
    You should have asked why the command doesn't work when opened from the Finder then, instead of the question you actually asked :). Also, pasting source code is also a very helpful thing. – Jason Salaz Feb 13 '12 at 8:39
  • @JasonSalaz No that question went to stackoverflow. Keeping my window open is a separate issue. – Kit Sunde Feb 13 '12 at 8:52
  • I remembered after the fact that .command is shell scripting and not Applescripting, which means it is off topic here on Ask Different. So, you did exactly the right thing. Thank you. – Jason Salaz Feb 13 '12 at 8:55

You must log in to answer this question.

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