2011-07-21 137 views
5

我的Applescript和Python脚本位于当前工作目录中。 现在我需要使用shell命令调用名为test.py的Python脚本和来自applescript的管理员权限。从Applescript调用Python脚本

这段代码在AppleScript的给

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

这段代码在AppleScript的调用从一个AppleScript的Python脚本手动

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

如何将presentDir添加到该命令沿着PWD具有管理员权限?

编辑和更新:

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

它给出了一个错误

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

但 显示对话框calldir 显示

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

原因:

由于空间原因,它在shell脚本命令中的'Microsoft'之后被分解。

回答

7

如果您知道脚本是在同一目录下,只需使用:

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

通知空间test.py收盘前引号之后。你可能需要的字符串是/test.py,而不是test.py,我不确定。

我从http://developer.apple.com/library/mac/#technotes/tn2065/_index.html了解到此信息。

编辑:尝试

set py to "test.py " 
set calldir to quoted form of workingDir & py 
do shell script calldir 
+0

因为test.py位于presentDir的同一目录中,我怎样才能忽略shell中”/ users/mymac/Documents /'Microsoft用户数据'/ test.py“的用法脚本命令。 – thinkcool

+0

林不知道我理解你的问题,但我用我最好的猜测编辑你的意思? – agf

+0

我已更新问题.. – thinkcool

0

您最初的剧本没有工作,因为你没有使用反斜线空格“\”本身: “/用户/ mymac /文件/微软\用户\ Data/test.py“