i have / want to run a shell command form my applescript that basically initiates a virtual machine etc
All is fine but, i would like to visual display within a text field the process and any feedback i can get form the shell command, in order then to execute more instructions and inform the user on the app that its complete etc.
So how can i get feedback after the script has completed and or during so i can then output to the user etc
i am using the code:
do shell script “???”
running on xcode 6.
Model: imac OS X 10.9
AppleScript: xCode 6
Browser: Safari 537.36
Operating System: Other
The code below returns the process number of the last job run in background.
set sh_res to do shell script " set n=1 & echo $!"
log sh_res
You should play safe, by executing do shell scripts in a try end try block, since the interpreter will balk, if the process returns with an non-zero error code.
set sh_res to do shell script "exit 5"
log sh_res
Here is something that may work better. Note the subshell, so that you insulate the do shell script command from throwing an error, which may be convenient in some situations.
try
set sh_res to do shell script "(exit 5 ); export a=$?; echo $a"
log sh_res
end try
I was reading this tutorial about launched the other day and at the end, in the Cookbook section, there was an interesting example. http://launchd.info/
At the end the instructions are:
Then, I guess the launch agent reads the file test.out. Not sure if this has something to do with what you’re trying and there a probably many ways to do what you want.
I know that your project is a completely different thing.
Edited: I didn’t see McUsr’s post. Just posted because nobody was answering.
your request seems to be related more to the AppleScriptObjC forum.
Search the ASObjC forum for NSTask, there are a few examples to capture stdout asynchronously
Appologies if it’s in the wrong thread, if a nadin can move it that would be great don’t want to double post, let me know if possible or will have to re post
You hit it right on the nose again with NSTask! It’s perfect for running shell scripts in AppleScript Objective C.
Edited: especially the waitUntilExit. This is the only way I’ve found to make the Cocoa program wait. Then, within your shell script you still want to output at certain points.