Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view stdout of script run within automator

I have a python script I want to be able to drag-drop files on to. So I've wrapped it in an Automator Application. Said Application has a single Run Shell Script with contents that look something like:

export PATH=${PATH}:/usr/local/bin:/usr/local/CrossPack-AVR/bin
cd /Applications/MyApp
/Applications/MyApp/doIt.py "$1"

This works. My python script runs with $1 showing up in its sys.argv[1]. Said script produces quite a bit of output though. I'd like to open some sort of window that shows the output as it happens. I don't mind if the user has to close it. I don't see anything in Automator's actions that do that. I've tried to do something like:

open -a Terminal /Applications/MyApp/doIt.py "$1"

Unfortunately, that doesn't seem to inherit the environment. Nor does it hand the $1 to the python script, but tries to open it as well.

So I'm looking for a way, to open something (Terminal or whatever) that can capture and scroll the stdout of that script while it runs, as invoked from within the script.

like image 959
Travis Griggs Avatar asked Feb 14 '23 11:02

Travis Griggs


2 Answers

In Automator arguments and variables can be passed using a special variable:

   $@

To get output from a script or task running in Automator you can click on the results (recessed button) below the script to see any output. Additionally you could setup another bash script to pass the output to stdout or wherever else you choose.

This example shows a python script sending output and variables to a bash script. You can pass input as arguments, or to stdin:

automator

like image 52
l'L'l Avatar answered Feb 16 '23 00:02

l'L'l


I am not at my Mac, so this is untested but I am pretty sure it can be made to work with minor edits...

Change your script so it looks like this and your python script runs in the background saving its output to a temporary file $$.tmp where $$ is your process id (pid):

export PATH=${PATH}:/usr/local/bin:/usr/local/CrossPack-AVR/bin
cd /Applications/MyApp
/Applications/MyApp/doIt.py "$1" > $$.tmp &

Now add the following lines at the end, so that you 1) create a script that tails your log file, 2) make it executable and 3) you execute it:

echo "tail -f $$.tmp" > x.command
chmod +x x.command
open x.command

I would recommend renaming x.command as $$.command so that you can run it multiple times from multiple users without interactions between the various users. You should also clean up and delete the temporary files after use.

like image 25
Mark Setchell Avatar answered Feb 16 '23 00:02

Mark Setchell