Page 1 of 1

calling python script from servoy

PostPosted: Sun May 07, 2017 2:04 pm
by irene.meyer1422261887
Hi,

I try to call a python script with an Applescript.

Code: Select all
var script = do shell script "python /Users/meyer/Documents/Projects/WoFOG/Code_Antonio/Loader_tracker.py -p /Users/meyer/Documents/Projects/WoFOG/ExpFolder/3001"
application.executeProgram('osascript',['-e',script ])


While the is working in ScriptEditor in servoy it does nothing. I don't even get an error and nothing is in the servoy.log.

It seams quite strait forward to me and I have not a clou why it doesn't work.

I would be grateful for any help.

Re: calling python script from servoy

PostPosted: Sun May 07, 2017 2:51 pm
by ROCLASI
Hi Irene,

application.executeProgram() doesn't allow spaces in the argument values. You need to put every argument in the array as it's own entry.
Also you don't have to use osascript to execute python. Just point to /usr/bin/python as your program.
So your code can look like this:
Code: Select all
application.executeProgram("/usr/bin/python", ["/Users/meyer/Documents/Projects/WoFOG/Code_Antonio/Loader_tracker.py", "-p", "/Users/meyer/Documents/Projects/WoFOG/ExpFolder/3001"])


Hope this helps.

Re: calling python script from servoy

PostPosted: Mon May 08, 2017 8:21 am
by irene.meyer1422261887
Hi Robert,

Thank you for helping, unfortunately it doesn't work. I already tried that one as many others but it seems I can't do the magic.

Just to be sure I tried your code on a simple python app that adds a new folder to a directory, but while it is working thru the terminal it doesn't work with executeProgram.
Code: Select all
application.executeProgram("/usr/bin/python", ["/Users/meyer/Documents/Projects/WoFOG/Code_Antonio/try.py"])


What I don't understand is that it doesn't return an error or some other kind of message, it is like that rule doesn't run. I tried many other ways, like make an .sh and call it, at least it returned a "permission denied" in the log. Now I know that Apple's integrity check is getting worst by the day, bit I don't want to disable it.

application.executeProgram() doesn't allow spaces in the argument values.

Probably I understand it the wrong way, but why is this working? It looks likes a lot of spaces to me :o
application.executeProgram('osascript',['-e','tell application "Finder" to say "David"']);

Re: calling python script from servoy

PostPosted: Mon May 08, 2017 8:40 am
by Andrei Costescu
Some ideas:
  • surround your "application.executeProgram" with a try/catch and see if it doesn't throw an exception (also check app. server log maybe)
  • which user runs the Servoy process in the OS? Does it have all the necessary permissions for the file(s) that you want to use?