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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With