我有这个applescript,它接受所选项目并压缩该文件/文件夹并使用名称作为zip名称。我遇到的问题是,当我解压缩 zip 时,它具有文件夹结构,所有路径从用户开始。
像这样:
Users:
username:
folder:
folder:
我只是希望它是:
folder:
这是代码:
tell application "Finder"
set theItem to selection as alias
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (theFolder & fileName & ".zip")
do shell script "zip -r " & zipFile & " " & itemPath
end tell
最佳答案
将 -j 开关添加到您的 zip 命令。换句话说,将“结束告诉”之前脚本的最后一行更改为:
do shell script "zip -jr " & zipFile & " " & itemPath
这应该告诉 zip 命令在创建 zip 文件的目录结构时将路径“垃圾”到您尝试压缩的任何内容。
关于使用applescript zip 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4909337/