[thechat] Fun little OS-X AppleScript

Bob Davis bobdavis at mac.com
Tue Apr 9 14:00:00 CDT 2002


I was playing around with using AppleScript for scripting terminal commands
and came up with this one. It's not terribly useful, but It's fun!

set dir to "$HOME"
try
    display dialog "What directory would you like a file count of?" & return
& return & ¬
        "Please Enter Path:" default answer dir
    set dir to the text returned of the result
    if dir is not "" then
        do shell script "cd " & dir & "; ls -l | wc -l"
        display dialog "There are" & result & "files in" & dir
    else
        error
    end if

end try


It just asks for a path to a directory, and counts the number of (non-dot)
files in it then throws up a dialog with the number of files.

It counts the files by issuing an ls -l command (no dot files shown) and
piping the output to wc (word count) with the -l flag (count lines).

Like I said, not too too useful, but kind of a hoot to play with.

What have you scripted on X?

Anything useful?


bob




More information about the thechat mailing list