如何使用 AppleScript-objc 压缩文件夹?
How to Zip folder with AppleScript-objc?
我在系统上生成一些日志,然后将其复制到 /tmp/MyFolder,然后
我将文件夹移动到桌面,我试图在您继续之前压缩它,但我不知道该怎么做,我尝试了以下操作:
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
虽然这不是 AppleScript-ObjC 脚本,但我发布了您自己的脚本的更正版本,以便它按照您描述的方式运行:
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 进行文件系统操作。听起来 counter-intuitive,但不是 well-suited。使用 系统事件 ,它具有处理 posix 路径的能力,以及许多其他好处。
脚本现在将文件夹及其包含的项目压缩到 /tmp/MyFolder.zip
的存档中,然后将此存档移动到桌面。
我在系统上生成一些日志,然后将其复制到 /tmp/MyFolder,然后 我将文件夹移动到桌面,我试图在您继续之前压缩它,但我不知道该怎么做,我尝试了以下操作:
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
虽然这不是 AppleScript-ObjC 脚本,但我发布了您自己的脚本的更正版本,以便它按照您描述的方式运行:
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 进行文件系统操作。听起来 counter-intuitive,但不是 well-suited。使用 系统事件 ,它具有处理 posix 路径的能力,以及许多其他好处。
脚本现在将文件夹及其包含的项目压缩到 /tmp/MyFolder.zip
的存档中,然后将此存档移动到桌面。