5

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.

0

2 Answers 2

7

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
Sign up to request clarification or add additional context in comments.

3 Comments

since test.py is in the same directory of presentDir, How can I ignore the usage of "/users/mymac/Documents/'Microsoft User Data'/test.py "in the shell script command.
Im not sure I understand your question, but I edited with my best guess for what you mean?
To quote var use quoted form of var.
0

Your initial script didn't work because you didn't escape the spaces with a backslash "\" as such: "/Users/mymac/Documents/Microsoft\ User\ Data/test.py"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.