Mac OS X'压缩'选项与命令行zip(为什么它们产生不同的结果?)

Loc*_*eyu 10 compression macos zip finder

我注意到命令行'zip'工具和Mac OS X的'压缩XXX'选项(通过右键单击查找器可用)提供不同的输出文件.文件的大小不仅要大几百字节,而且内容也要大不相同.

如何找出Finder用于压缩的命令?

Mar*_*ler 20

答案是man ditto:

 The command:
       ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip
 will create a PKZip archive similarly to the Finder's Compress function-
 ality.
Run Code Online (Sandbox Code Playgroud)

  • 不完全是,不。`ditto` 使用相同的算法。您看到的可能只是压缩级别的不同设置。在这两种情况下,您可以使用“zip -9”或“ditto --zlibCompressionLevel 9”来获得最佳(也是最慢)的压缩。此外,“ditto”可能比 zip 保存更多的内容,例如资源分叉、扩展属性和访问信息。 (2认同)

Par*_*fna 4

查看用于压缩 Finder 选择的 AppleScript文章。

try
    tell application "Finder"
        set theSelection to the selection
        set selectionCount to count of theSelection
        if selectionCount is greater than 1 then
            error "Please select only one Finder item before running this script."
        else if selectionCount is less than 1 then
            error "Please select one Finder item before running this script."
        else
            set theItem to (item 1 of theSelection) as alias
            set destFolder to (container of theItem) as alias
            set itemName to name of theItem
        end if
    end tell

    do shell script ("ditto -c -k --sequesterRsrc --keepParent " & quoted form of POSIX path of theItem & space & quoted form of (POSIX path of destFolder & itemName & ".zip"))
on error theError
    tell me
        activate
        display dialog "Error: " & theError buttons {"OK"} default button 1 with icon stop
    end tell
end try
Run Code Online (Sandbox Code Playgroud)