使用 applescript 压缩 zip 文件夹
我有这个 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
I have this applescript that takes the selected item and zips that file/folder and uses the name as the zip name. The problem I have is when I unzip the zip it makes it has a folder structure all of the path from User on up.
Like this:
Users:
username:
folder:
folder:
I would just like it to be :
folder:
Here is the code:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 -j 开关添加到您的 zip 命令中。换句话说,将“end Tell”之前脚本的最后一行更改为:
这应该告诉 zip 命令在创建 zip 文件的目录结构时将您尝试压缩的任何内容的路径“垃圾化”。
Add a -j switch to your zip command. In other words, change the last line of your script before "end tell" to:
That should tell the zip command to "junk" the path to whatever you're trying to compress when it makes the directory structure for the zip file.