# Applescript/Terminal Question?



## buc99 (Dec 17, 2002)

I have a script that asks for a file name and then opens a specific directory and inside the terminal. It then opens vi within the terminal with that filename:

display dialog ¬
	"Please enter name of project file:" default answer "samp.c" buttons {"Ok", "Cancel"} ¬
	default button "Ok"
if button returned of result = "Ok" then
	set z to text returned of result
else
	exit repeat
end if
tell application "Terminal"
	do script "pushd Sandbox/Programming/Code_src/C"
       do script "vi " & z
end tell

The problem here is that (#1, I'm not a very prolific Applescript programmer. But besides that ...) if the terminal is not open this script will open a terminal window, open another terminal window and launch the command "pushd Sandbox/Programming/Code_src/C", and then open another window and execute the command '"vi " & z'.  I would like the applescript to just open one terminal window and then launch the two unix commands inside that one single window so that I have only one terminal window open when it is all said and done.  One way to get the two commands to execute sequentially in one window is to change the 'do script' lines to:

	do script "pushd Sandbox/Programming/Code_src/C; vi " & z

This is basically a Unix fix and I still have two terminal windows open if the Terminal.app is not already active.  So how do I accomplish my gaol in a more 'Applescript' kind of way?

Thanks in advance.
SA


----------



## gatorparrots (Dec 17, 2002)

Remove the *tell application "Terminal"*.
Call your shell commands with:
do shell sript "/path/to/executable -flags"


----------



## buc99 (Dec 17, 2002)

Nope.

That does not work for the pushd command. All I get is a Terminal window with no change in pwd.  i want the first window that pops open to change directories to a specific directory using the "pushd" command.  

do shell script "pushd /whatever/Directory/I/Wish/to/Change/to"

This does not work because there is no where to direct the output to the command.  This however does do nicely for some unix commands that print their output to the screen(Except top).

Thanks.
SA


----------



## scaryfish (Dec 27, 2002)

Stick "in window 1" to the end of your do script commands.  Like this:

do script "pushd Sandbox/Programming/Code_src/C" in window 1

And that'll do it in the first window that was opened (or that opens when Terminal launches)


----------

