Run shell script in background problem

In the Apple Technote TN2065

It states to use the syntax do shell script “command &> file_path &”

However, I would like to use a longer and variable command.

For instance previously, I would use a variable to store the commands and then do shell script.
set custom_command to " various commands "
do shell script custom_command

However, this does not work with the above syntax:

do shell script “custom_command &> file_path &”

I get the error message “sh: line 1: custom_command: command not found”

Is there a solution to this?

The reason I ask, is that I have a shell script that can take up to 20 minutes to complete and I want the user to get some feedback as to what is happening. Currently, I have the Terminal open and run the script as visual feedback, but I rather have my app show the feedback instead.

What I wanted to do was as the Technote stated:

Any ideas will be appreciated.

Try something like this:

set command to "ls ~"
do shell script command & " &> ~/example.txt &"


Thank you so much!

Now the next step… how can I read the text file and output it in relative realtime?

I tried something like this:

do shell script command & " &> ~/example.txt &"
set text_loc to ":example.txt" (EDIT: Not actual path to file, just an example)
set theText to (read file text_loc)
set content of text field "output" of window "Main" to theText

EDIT: Error fixed: (But I get a “End of file error (-39)”)

It will output to the text field once, but I would like it to continue to update the text field as the script is running and writing to the file example.txt

Any ideas?

Unlike the shell, AppleScript expects colon separated paths (HFS path)

set text_loc to ((path to home folder as text) & "example.txt")


Sorry, I was being sloppy in my example, I’m not actually using set text_loc to “~/example.txt”
The actual path was colon separated.

So that was not the source of the problem.

EDIT: I found the solution to the end of file error message. I needed to add a slight delay before having Applescript read the file.

However, I would still like to have the output be displayed in a relatively real time manner, one line at a time.

Any suggestions?

None that involve AppleScript Studio.

Have a look at Bruces progress bar