从Applescript调用Python脚本

时间:2011-07-21 20:13:39

标签: python macos shell applescript

我的Applescript和Python脚本位于当前工作目录中。 现在我需要使用shell命令从Apple脚本中调用名为test.py的Python脚本。

Applescript中的此代码提供了pwd

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与Admin权限一起添加到此命令?

编辑和更新:

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'一词后被打破了。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

你的初始剧本没有用,因为你没有用反斜杠来逃避空间#34; \"因此: " / Users / mymac / Documents / Microsoft \ User \ Data / test.py"