Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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.

EDIT:

  • 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.)

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.