views:

94

answers:

1

Here's an interesting problem: Using the AppleScript method to launch a new command in a Terminal window fails if Terminal is "busy"; more precisely, it will open a new window but fail to run the command. For example, try copy+pasting this line in:

osascript -e 'tell application "Terminal" to do script "foo"'; osascript -e 'tell application "Terminal" to do script "bar"'; osascript -e 'tell application "Terminal" to do script "baz"';

When I run this (I'm on Snow Leopard), I get three windows: In the first, the command foo is run, as expected; but in the other two, I just get an empty prompt. And I get empty prompts in all three windows if I've just pasted the command in; apparently Terminal is still busy processing the "paste" operation.

Now, AppleScript might not be the best way of doing this, but I really want to write a script that launches a bunch of Terminal windows, in order, and runs a command in each. Maybe the best way to do that is with a bash script. As long as I can create an alias to it, I'm happy. So how to do this?

+2  A: 

what are the actual scripts you are running

I modified your code alittle to test it

osascript -e 'tell application "Terminal" to do script "cd Desktop"'; osascript -e 'tell application "Terminal" to do script "cd .."'; osascript -e 'tell application "Terminal" to do script "ls"';

and this seems to work fine

mcgrailm
The first time I ran the script, the first two Terminal windows froze up and only the third one ran the script. The second time, the first one ran and the other two windows froze up. (By "froze up," I mean that nothing executed in them and I couldn't enter text in them, which was the same problem I was having before.) So maybe it's something odd about my setup.
Trevor Burnham
Confirmed: I commented out my `.bashrc` and everything worked fine. So now I just need to figure out what's causing problems in there. Thanks!
Trevor Burnham