useing a specific window...

Hey,
I’m pretty new to the scripting stuff, and just want to have a script that will put a cmd into a window that is already open, heres what i have so far


tell application "Terminal"

	do script with command "sudo" in window "1"

end tell

i think it is right, but when i run it i get an error:

“terminal got an error:
NSArgumentEvaluationScripError”

what am i doing wrong, and what does this error mean?

thanx

Terminal’s dictionary says that ‘with command’ is deprecated. You have also coerced 1 to text by enclosing it in quotes - it probably needs to be a number. Does this work?

tell application "Terminal"
	do script "sudo" in window 1
end tell

well i dont get the error anymore with your code, but it doesn’t do the command either :confused: it just opens up bounces a lil and shuts down, not doing what i want it to heh.

I’m not familiar with sudo but I think that just ‘sudo’ is an incomplete command.

Rob is correct, sudo alone will not work. You can use “sudo -k” in the code. The -k arguement simply resets the sudo users time stamp to 0. Or you can use “sudo sh” in the code. Also the “with command” has been dropped in later versions of the AppleScript. So, try this code

tell application "Terminal"
	
	do script "sudo sh" in window frontmost
	
end tell

The above code needs to have an open terminal window. Hope that helps.

well i’m not doing the sudo comand at all, it was just an example heh, but the frontmost thing works in a regular window, but i was trying to make it do it in an eDonkeyClc window, but there is obviously another prob, beacuse it doesn’t work with eDonkey. I was thinking that beacuse it ran in the terminal that it would just treat it as another window, but it does not. so thanks anyway for your help :?

It might have been helpful to know this up front. :expressionless:

Are you aware that you can issue shell commands directly from a script, without using the Terminal? If you don’t actually need a window, this might be useful.

do shell script "shell command here"

:slight_smile:

it gives me an error now :confused:

heres the code:

tell application "Terminal"
	
	do shell script "vd"
	
end tell


i tried it with adding in window frontmost, but then it gives me another error about access not allowed. ARGGG.

:shock: It wasn’t meant to be used in a Terminal script. Try this code, and only this code, in an AppleScript script.

do shell script "vd"

If you need whatever is returned by the command, if anything is returned, you can capture it in a variable (foo in this example):

set foo to do shell script "vd"

:slight_smile:

well, now i get another error “sh: vd: command not found” , i have exactly what you have :? …and what does the sh mean, shell?

Dunno what sh means except to be quiet. What happens when you run the command in Terminal? Is it possible that the target of the command is located in a non-standard directory? I’m no shell/unix expert so I can only guess. :?

well the vd command in eDonkey(eDonkey runs in the terminal) is to view your downloads, all i want the script to do for know is automatically enter the vd command…gah i feel so stupid I think i’m just going to give up, but thanks for your help rob and greg.

What it means is that whatever shell you are using in the Terminal (ie, tcsh, bash, ksh, zsh, or whatever) is not the shell that the ‘do shell script’ command uses. Even the default shell of Terminal knows/does more than the default shell of ‘do shell script’.

I’d highly recommend that you go read the following document from Apple, which explains the problems you’re facing and what to do about them: http://developer.apple.com/technotes/tn2002/tn2065.html

In your specific case, you probably just need to ge the full path to vd to run it. For example, if vd is at /usr/local/bin/vd you’d need to run the following (NOT in a tell Terminal block):


do shell script "/usr/local/bin/vd"