ApplescriptObjC文件夹路径

时间:2015-06-11 14:51:37

标签: applescript

我目前正在设置ApplescriptObjC应用程序。每当我尝试其他方法时,它就会搞砸了。我正在尝试将其设置为shell脚本使用mv命令将文件从“Files”目录移动到/ usr / bin /文件夹。我认为这会有点像:do shell script "sudo mv " & path & "/Files/ /usr/bin/"路径将是我的路径。我已经尝试了通往我和posix等路径的路径,但是没有用。 ![Files文件夹包含我要移动到/ usr / bin的文件]文件夹所在的图像:http://i.stack.imgur.com/jUX6w.png

1 个答案:

答案 0 :(得分:1)

首先,屏幕截图中的文件夹Files是Xcode中的虚拟文件夹(黄色)。 你必须创建一个真正的文件夹(蓝色)。最简单的方法是将Finder中的文件夹拖到Xcode侧栏并选择"创建文件夹引用"

要在AppleScript中使用sudo,请将with administrator privileges添加到do shell script行。系统将提示您输入管理员密码。

此代码将(!)文件移动到/usr/bin。如果您要复制(复制)文件,请使用cp -r代替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
相关问题