applescript 中的 "Do Shell Script" 命令在脚本编辑器中有效,但在我的 cocoa applescript 应用程序中无效

"Do Shell Script" command in applescript works in script editor but not in my cocoa applescript application

所以我在 applescript 中制作了一个脚本,它使用 "do shell script" 命令来 运行 google 应用程序管理器的终端命令(如果你不知道那是什么,那并不重要).我正在制作一个 cocoa applescript 应用程序,并希望将此脚本包含在功能中。该脚本基本上为用户重置密码。

下面我在脚本编辑器和 xcode 中提供了脚本。我 运行 遇到的问题是,当我通过脚本编辑器 运行 时脚本工作正常,但当我在 xcode 中 运行 它时它不起作用。错误如下以粗体显示。

--

2015-08-11 18:49:03.205 DMA 技术团队[16153:1910832] *** -[AppDelegate 密码重置:]: python: 无法打开文件 'Users/Nikhil/Desktop/gam/gam.py': [Errno 2] 没有那个文件或目录(错误 2)

奇怪的是,我的 "gam" 目录和 "gam.py" 文件都在正确的位置,所以应该不会有错误。

我想知道我是否需要为此做一些特别的事情,这在 applescript obj c 中与在 plane applescript 中有所不同?

注意 "CTN" 只是一个电子邮件地址。 checkEmail() 是一个检查输入的电子邮件是否已经存在的函数,它不是错误的原因。

脚本编辑器中的脚本

set User to short user name of (system info)

display dialog "What is the ctn?" default answer ""
set theCTN to text returned of result

display dialog "What is the new password?" default answer ""
set thePassword to text returned of result

do shell script "python Users/" & User & "/Desktop/gam/gam.py update user " & theCTN & " password " & thePassword

Xcode 的应用程序委托中的脚本

 on Passwordreset_(sender)

    set User to short user name of (system info)

    set theCTN to RESETPASSIND_CTN's stringValue() as text

    set thePassword to RESETPASSIND_PASSWORD's stringValue() as text

    do shell script "python Users/" & User & "/Desktop/gam/gam.py update user " & theCTN & " password " & thePassword

 end Passwordreset_

谢谢!!

您正在使用相对路径名 (Users/...) 而不是绝对路径 (/Users/...)

XCode 项目往往从一个不起眼的项目构建目录开始。 大概(我没有检查过)脚本编辑器是从“/”开始的。