I’ve been working with an applescript that uses shell scripts to do some file copies. The script itself works fine, but I’m trying to create logs with information about what just happened. I can capture output of all kinds of scripts from do shell script by just setting it to a variable.
set theVar to do shell script "whoami" -- This works just fine
return theVar
The problem is with the cp and ditto commands. I’ve flagged them as verbose, and they just don’t return any output. Here’s an example:
set theVar to do shell script "sudo ditto -V -rsrc '/Volumes/acomData/Misc./Preference\ Profiles/Art Director:Graphic\ Artist/User Preferences/' '/Users/user/Library/Preferences/';"
return theVar --returns an empty variable
The command works fine from a terminal. I see the Verbose output as flagged. The script works too, as I can see the effects of it, but I just can’t capture the output! Do you have any suggestions?
FYI, I pretty much have this one figured out. You have to capture standard error - not standard out for commands such as ditto. to do this you use syntax like this:
comand -arguments 'whatever else' > path to your standard out file 2> path to your standard error file
You can also use >> to make a file append, so you could redirect both outputs into the same file and run extra stuff in them over time.