Trouble with shell commands

While trying to use some shell commands from Mac OS X 10.1 I ran into a lot of problems, many commands were unavailable. I get the error message “zsh: command not found: ”. disktool, for example, is one of the commands I can use at the command line, but AppleScript returns an error on. Also, why is AppleScript using zsh instead of tcsh?

The chances are the $PATH is not set to include the directories your shell command is in.

For various reasons, the ‘do shell script’ does not use the same environment as your normal shell account. This means that if you use a login script such as .profile, .tcshrc, etc. to modify your $PATH, these changes will not be seen by ‘do shell script’

The solution is easy. Include the full path to the command in your shell script. i.e. instead of:

do shell script “disktool”

use:

do shell script “/usr/sbin/disktool”

This is always a good practice in any shell environment. It makes sure you target the process you expect and not some other random process that may happen to have the same name.

Because tcsh is a “C shell,” not a Bourne compatible shell, which is what most people prefer to script in.

The Do Shell Script in Applescript technote is very informative and a worthwhile read. It contains this info: