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.
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.
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
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