简体   繁体   中英

Can't run custom bash script in Applescript

Here is my code:

set scriptpath to (path to current application as text)
set scripty to do shell script scriptpath & "Contents:Resources:moveskript " & variable1 & variable2 with administrator privileges

And it says this:

2015-12-08 16:40:33.565 Move[9093:63037] *** -[AppDelegate mybuttonhandler:]: /bin/sh: HD2:Users:gff:Library:Developer:Xcode:DerivedData:Move-fxtmdhtebdbqpbemfeknbexosigm:Build:Products:Debug:Move.app:Contents:Resources:moveskript: command not found (error 127)

Even though the command is there, and it works when I run it through terminal.

The "Contents:Resources:moveskript" syntax is for Finder path object, not a POSIX path.

Mistakes:

  1. Combine full path: set moveScriptPath to (path to me as string) & "Contents:Resources:moveskript"
  2. Get POSIX path: set posixPath to POSIX path of moveScriptPath

Currently the path is causing the error 127. After fixing that, if you "moveskript" doesn't have any errors it should be fine. Look out for paths with spaces, special characters etc., use quoted form of somePathWithWhitespace in apple script. More info .

This 'moveskript' , guessing from the name, it moves two to place where user might not have read/write privileges, FYI there is a shell command mv just for that. Open Terminal and type man mv to read more about it. Also is it an apple scrip too? Why not just use a handler inside the same script? If so you have to do:

do shell script ("/usr/bin/osascript " & quoted form of posixPath & " " & quoted form of file1 & " " & quoted form of file 2) with administrator privileges

I'm guessing you're calling this from an application and not applet, so there is not need to use applescript to move stuff, again look into mv . Even better use the Cocoa framework because it can do all the work, more info .

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