ApplescriptObjC Path To Folder

243 views Asked by At

I am currently setting up an ApplescriptObjC application. Whenever I try other methods, it screws up. I'm trying to set it up where a shell script uses the mv command to move a file from the "Files" directory to the /usr/bin/ folder. I think it would go a little something like: do shell script "sudo mv " & path & "/Files/ /usr/bin/" where path would be the path to me. I have tried the path to me and posix and other stuff, just doesn't work. ![The Files folder contains a file I want to move to /usr/bin] Image of where the folder is: https://i.stack.imgur.com/jUX6w.png

1

There are 1 answers

0
vadian On BEST ANSWER

First of all the folder Files in your screenshot is a virtual folder in Xcode (yellow). You have to create a real folder (blue). The easiest way is to drag a folder in Finder to the Xcode sidebar and select "Create folder references"

To use sudo in AppleScript append with administrator privileges to the do shell script line. You will be prompted to enter an admin password.

This code moves(!) the files to /usr/bin. If you want to copy (duplicate) the files use cp -r instead of mv

   set filesFolder to (current application's NSBundle's mainBundle()'s resourcePath()'s stringByAppendingPathComponent:"Languages") as text
   tell application "System Events" to set filesToMove to name of files of folder filesFolder
   repeat with aFile in filesToMove
     do shell script "/bin/mv " & quoted form of (filesFolder & "/" & aFile) & space & "/usr/bin/" with administrator privileges
   end repeat