首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用AppleScript-objc压缩文件夹?

如何使用AppleScript-objc压缩文件夹?
EN

Stack Overflow用户
提问于 2019-06-18 23:35:43
回答 1查看 2.7K关注 0票数 0

我正在系统上生成几个日志,然后将其复制到/tmp/MyFolder,然后将文件夹移到桌面上,在您继续之前,我正在尝试压缩它,但我不知道如何做,我尝试了以下方法:

代码语言:javascript
复制
tell application "Finder"
    set theItem to "/tmp/MyFolder" 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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-19 00:31:01

虽然这不是一个AppleScript-ObjC脚本,但我发布的是您自己脚本的修正版本,这样它的功能就像您所描述的那样:

代码语言:javascript
复制
tell application "System Events"
    set itemPath to "/tmp/MyFolder"
    set theItem to item itemPath
    set fileName to quoted form of (get name of theItem)
    set theFolder to POSIX path of (container of theItem)
    set zipFile to fileName & ".zip"
end tell

do shell script "cd " & quoted form of theFolder & ¬
    "; zip -r " & zipFile & space & fileName & ¬
    "; mv " & zipFile & space & "~/Desktop/"

试图避免在文件系统操作中使用Finder。这听起来违反直觉,但不太适合。使用系统事件,它具有处理posix路径的能力--其中包括许多其他好处。

该脚本现在将文件夹及其包含的项压缩到/tmp/MyFolder.zip的存档中,然后将该归档文件移到桌面上。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56658320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档