简体   繁体   中英

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

So I made a script in applescript that uses the "do shell script" command to run a terminal command for google apps manager (if you dont know what that is,it isnt important). I am making a cocoa applescript application and wanted to include this script in the functionalities. The script basically resets passwords for users.

Below I have provided the script in script editor and in xcode. The problem I am running into is that the script works just fine when I run it through script editor but it doesn't work when I run it in xcode. The error is as follows in bold.

--

2015-08-11 18:49:03.205 DMA Tech Team[16153:1910832] *** -[AppDelegate Passwordreset:]: python: can't open file 'Users/Nikhil/Desktop/gam/gam.py': [Errno 2] No such file or directory (error 2)

The weird thing is that my "gam" directory and "gam.py" file are all definitely in the correct place so there shouldn't even be an error.

I was wondering if there is something special I have to do for this that is different in applescript obj c than in just plane applescript?

Note "CTN" is just a email address. checkEmail() is a function that checks to see if that email entered already exists, it is not the reason for the error.

Script in Script Editor

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

Script in Xcode's app delegate

 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_

Thanks!!

You are using a relative pathname (Users/...) instead of an absolute path (/Users/...)

XCode projects tend to start in an obscure project build directory. Presumably (I haven't checked) the Script Editor is starting in "/".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM