Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a Python script from a Applescript

My Applescript and Python script are in the present working directory. Now I need to call the Python script named test.py with admin privileges from the applescript using shell commands.

This code in Applescript gives the pwd

tell application "Finder" to get folder of (path to me) as Unicode text
set presentDir to POSIX path of result

This code in Applescript calls a python script from an Applescript manually

do shell script "/Users/mymac/Documents/'Microsoft User Data'/test.py"

How to add the presentDir to this command along with Admin privileges?

EDIT and UPDATE:

set py to "test.py "
set calldir to workingDir & py
do shell script calldir

It gives an error

error "sh: /Users/mymac/Documents/Microsoft: No such file or directory" number 127

But display dialog calldir shows

/Users/mymac/Documents/Microsoft User Data/test.py

Reason:

it gets breaked up after the word 'Microsoft' in shell script command because of space.

like image 339
c_prog_90 Avatar asked Jul 21 '11 20:07

c_prog_90


People also ask

Can I run Python on BBEdit?

To write Python programs with a simple text editor you will want to use a text editor that offers support for the Python language: I recommend BBEdit for Mac OS X or NotePad++ for Windows. If you would like to use an IDE, I recommend the PyCharm Community Edition IDE.


1 Answers

If you know the script is in the same directory, just use:

do shell script presentDir & "test.py " user name "me" password "mypassword" with administrator privileges

Notice the space after test.py before the close-quote. You may possibly need the string to be /test.py, rather than test.py, I'm not sure.

I got this info from http://developer.apple.com/library/mac/#technotes/tn2065/_index.html.

Edit: Try

set py to "test.py "
set calldir to quoted form of workingDir & py
do shell script calldir
like image 108
agf Avatar answered Oct 11 '22 22:10

agf