Terminal Commands given in AppleScript

I’ve been working on an AppleScript that opens up Terminal and runs some commands. I can open terminal but I don’t know which command to use to type the terminal command. ie:
tell app “Terminal”
“unknown command” “cd /users/ianholm/documents”
end tell

So if someone could tell me that command, that would be great.

This should work for single commands.

tell application "Terminal"
	do script "cd /users/ianholm/documents"
end tell

– Rob

This should work for single commands.

tell application "Terminal"
	do script "cd /users/ianholm/documents"
end tell

I’ve the same problem. I need to give 2 commands: a “cd” command and a “sudo” is it possible? Is there another way to launch as a superuser an app.? Through a finder applescript? Thx


there are three options.

#1 In the most cases it’s not necessary to open the terminal.
This might be sufficient

do shell script "cd /users/ianholm/documents"

#2 You can put multiple commands in one line separated by semicolon(s)

do shell script "cd /users/ianholm/documents; ls -a"

#3 Include the path in the second command

do shell script "ls -a /users/ianholm/documents"

Thanks StephanK,
I can’t find the way. The problem is that to access my proxy server I have to give some terminal commands (to activate Stunnel) and it’s quite annoying. So I’m trying to find out a way to do it automatically on launch. Tried with automator (find the executable file and opening it) but it doesn’t work. So I’m trying with a script.
The commands are:

cd /opt/local/sbin

sudo .stunnel

and then type my password

any hints? Thx from a noobie

Sorry Stephan, I made a last try and apparently works:

do shell script "cd /opt/local/sbin; sudo ./stunnel" password "paris" with administrator privileges


Are your sure, you mean a folder /opt/local/sbin, not /usr/local/sbin?
Anyway, try

do shell script "/opt/local/sbin/.stunnel" password "mypassword" with administrator privileges

Note: mypassword ist the admin password of OS X

Don’t use sudo and adminitrator privileges in the same line, it means the same thing

Technical Note TN2065: do shell script in AppleScript