Timothy Vann Timothy Vann - 6 months ago 67
AppleScript Question

How do I use AppleScript to time program execution

I would like to use AppleScript to batch run a bunch of programs and get the time that each one ran.

Example: From the command line I would type

time ls
like this:

$ time ls
Applications
bin
net
Library
... etc

real 0m0.013s
user 0m0.002s
sys 0m0.006s


but when I try to use apple script and put the results into a variable, it completely ignores the time output.

Example:

set result to do shell script "time ls"


returns

Applications
bin
net
Library
... etc


with no mention of the time execution time anywhere.

Even making this more simple:

set result to do shell script "time"


returns

""


How do I get the time of execution back from AppleScript?

p.s. I'm not actually trying to time
ls
. I want to time a bunch of custom created programs, but
ls
makes simple example.

Answer Source

Use the exec 2>&1 command to redirect the STDERR to STDOUT, like this:

do shell script "exec 2>&1; time  ls"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download