osascript.py icon indicating copy to clipboard operation
osascript.py copied to clipboard

How to return result to calling app?

Open pauljvallance opened this issue 7 years ago • 1 comments

you show how to return a result to a dialog box on screen e.g

code,out,err = osascript.run('display dialog "Finished"')

I would like to return a result such as a string of text directly to my calling app ( which is XOJO sending a shell command to Terminal to do script xyz.py. I can get around this by using your osascript.run to call an applescript from within the python script which then sends a custom AppleEvent back to my calling app. it seems that an OSAScript call to run a Python script in MacTerminal returns the id of the Terminal Window.

pauljvallance avatar Dec 22 '18 10:12 pauljvallance

if I understand everything correctly, then you need to execute the command in a new Terminal.app window and return the output string?

in that case you need some wrapper. for example, with .command

/tmp/$$.command

#!/usr/bin/env bash

command > /tmp/$$.log
mv /tmp/$$.log ~/app.log

chmod +x /tmp/$$.command open -a Terminal /tmp/$$.command while ! [ -e ~/app.log ]; do sleep 1; done output="$(cat ~/app.log)"

andrewpetrochenkov avatar Dec 22 '18 12:12 andrewpetrochenkov