"See" shell scripts in action with applescript
Alec Jacobson
September 13, 2009
Here's a simple script to open Terminal.app and execute a shell script.
tell application "Terminal"
activate
do script "ls"
end tell
Note: Note the subtle difference from another applescript feature you might be used to, namely do shell script
. The latter, do shell script
, when executed anywhere in an applescript runs a script at root level (but without root permissions). So running a script like:
set contents to do shell script "ls"
The variable contents
will hold the return of ls
for the root directory, /
. On the other had something like the code at the top will execute ls
at the default location of a new Terminal window, which (unless you have changed it) is by default the home directory of the current user. So in a Terminal tell block,
do script "ls"
opens a new terminal window and executes ls
in that window, presumably at the user's home directory, ~
.