使用Applescript / Terminal复制文件

时间:2014-05-19 02:48:14

标签: macos shell terminal copy applescript

我正在编写一个使用applescript的程序,它将使用“osacompile”terminal命令编译一个单独的应用程序,然后将原始文件的包内容中找到的文件(不是通过osacompile创建的文件)复制到包中osacompiled应用程序的内容。但是,我甚至无法将所选文件移动到桌面或文档文件夹。

我尝试了几种方法,例如“cp”命令和“tell application Finder”命令。在下面粘贴的破损脚本示例中,我尝试使用“cp”命令。

这是脚本:

set MusicFile to (path to me) & "Contents:Resources:CountryPackages:Soviet Union:SovietMusic.mp3"

set SovietUnion to "display dialog \"ok\""

set DesktopPath to (path to desktop)

do shell script "osacompile -x -o ~/Desktop/SovietUnion.app -e " & quoted form of SovietUnion

set DuplicateDestination to (path to desktop as alias) & "SovietUnion.app:Contents:Resources:"      

do shell script "cp -RfXv " & MusicFile & DesktopPath

1 个答案:

答案 0 :(得分:2)

有些路径看起来不正确。在shell脚本中,您应该使用UNIX路径。

set MusicFile to ((path to me) as text) & "Contents:Resources:CountryPackages:Soviet Union:SovietMusic.mp3"

set DuplicateDestination to alias (((path to desktop) as text) & "SovietUnion.app:Contents:Resources:")  

do shell script "cp -RfXv " & quoted form of POSIX path of MusicFile & space & quoted form of POSIX path of DesktopPath