Scripting a Terminal window and executing commands

I’m trying to write a script that will open a terminal window and execute a couple of commands, one of which will remain running in the window (this is to avoid the suggestion that I use “do shell script”). However, I am unable to make even the simplest “do script” command work. Here is some sample code:

tell application "Terminal"
	set scriptCommand to "cd " & " /"
	do script scriptCommand
end tell

[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

The script doesn’t create a new window and it doesn’t execute the cd command in Terminal’s current window (it does, however, activate Terminal :wink: )

I tried this script on three computers (a G4 450 DP, OS X 10.3.2, a TiBook 667, OS X 10.3.2, and a G3 300, OS X 10.2.8 ) . Same results.

I’m running Terminal 1.4.1 (v100)
Script Editor 2.0 (v43)
Applescript 1.9.3
(except on the G3)

It seems like I have something broken somewhere; I’m looking for trouble-shooting ideas.



Your script works exactly as expected on my machine. Not sure what to tell you.

What happens if you do it in one statement:

tell application "terminal" to do script "cd /"


It works just fine for me (10.3.2 12" PB).

I’m wracking my brains trying to figure out what would keep it from working on your Macs.

  1. I tried the single-liner script and it didn’t work.
  2. My partner came into my office with her G3 firewire PowerBook.
  3. We tried the one-liner script on her machine. It worked.
  4. Back to the G4. It didn’t work.
  5. Quit Terminal and Script Editor.
  6. Restarted Script Editor. Typed in the one-liner. It worked. (What’s weird is that, in my previous struggles, I had restarted the computer and the script still hadn’t worked…)
  7. Went to the G4 PowerBook. Quit Terminal and Script Editor. Typed in the one-liner. It worked.
  8. Same thing on the beige G3.
  9. Entered in the multi-line program. It worked.

I don’t know what to say, and I don’t know why things started working. But they do. Must be your good vibes.



You might want to try:

do shell script "cd /"

As a single line of code, which worked on my machine (iBook G4), though I guess I can’t judge quite exactly, since I don’t know what it does. Regardless, it did a thing and didn;t give me any errors. I’m also having a similar problem with something like that. I’m having trouble getting this to work, in an Application context:

do shell script "diskutil repairPermissions /" password thePass with administrator privileges

The variable thePass is predetermined, and that’s not the problem. I can do the same thing in an AppleScript file, and it works perfectly. However the same thing in the application gives me an error. This is the error it gives me:

Any suggestions?

Can you clarify what you mean? Which application? Terminal? If you are sending the command to Terminal from a script, the command is different than when using ‘do shell script’.

Without Terminal: do shell script “theCommand”

With Terminal: do script “theCommand”

– Rob