AppleScript Zip 文件夹内容,不包含任何文件夹
AppleScript Zip contents of folders without including any folders
我正在尝试编写将执行以下操作的 apple 脚本应用小部件。
当您将多个文件夹拖到小部件上时,它会将每个文件夹的内容压缩为一个单独的 zip,这些 zip 将与小部件位于同一目录中。
我遇到的问题是我不知道如何删除初始文件夹,当您解压缩存档时,它需要所有文件和子文件夹都松散。
例如,如果我压缩 myFolder/index。html
和 myFolder/img/myImage.png
它应该像 index.html 和 img/my image.png
一样解压
这对我来说非常有用,我每天必须将文件夹的内容压缩大约 50 次,用文件夹的名称重命名压缩文件并将它们复制到父文件夹中。
如果有人可以提供帮助,我愿意提供神秘奖品,我有大量的 Steam 钥匙!
谢谢
将
这应该可以帮助您入门。如果您不理解某个行为,请随时提问。
on open theFiles
repeat with x in theFiles
set _path to POSIX path of x
tell application "Finder"
if kind of x is "Folder" then
tell me to zipFolder(_path)
end if
end tell
end repeat
end open
on run
-- Handle the case where the script is launched without any dropped files
open (choose folder with multiple selections allowed)
end run
on zipFolder(theFolderPath)
do shell script "cd " & quoted form of theFolderPath & " && zip -r \"../$(basename $(pwd)).zip\" ./"
end zipFolder
这是 full applet 此外,您可能还想看看 LaunchBar、Alfred 和 Keyboard Maestro 等应用程序,它们有助于创建这样的操作。有一些用于存档的应用程序,例如 Archiver 和 Entropy,它们带有诸如此类的操作。
如果您想学习 applescript,可以考虑添加以下功能。
- 让小程序请求存档的名称,并使用它。
显示对话框处理程序,并将结果作为第二个参数传递给 zipFolder 处理程序
- 创建文件后在Finder中显示文件。
告诉 Finder 显示
- 将存档移动到特定目录以上传它,例如投递箱
告诉 Finder move/copy,或 bash 命令 mv
- 让小程序也处理文件。如果你想要它的任何行为。
其他人只能帮助你这么多,因为他们可能无法完全理解你所面临的困境,所以学习这一点会非常有用,而且很有趣。
对于任何感兴趣的人,这是我使用的最后一个脚本。此脚本获取任何选定的文件夹并从每个文件夹创建一个 zip 存档,将它们重命名为文件夹名称并且不包括 zip 中的根文件夹。这对于制作 Flashtalking HTML5 横幅特别有用。
on run {input, parameters}
if input is {} then -- no dropped items
tell application "Finder" to set input to selection as alias list
end if
repeat with x in input
set _path to POSIX path of x
tell application "Finder"
if kind of x is "Folder" then tell me to zipFolder(_path)
end tell
end repeat
end run
on zipFolder(theFolderPath)
do shell script "tDir=" & (quoted form of theFolderPath) & "; cd \"$tDir\"; aZip=\"../$(basename \"$tDir\").zip\"; if [ -e \"$aZip\" ]; then rm \"$aZip\"; fi; zip -r \"$aZip\" ./"
end zipFolder
我正在尝试编写将执行以下操作的 apple 脚本应用小部件。
当您将多个文件夹拖到小部件上时,它会将每个文件夹的内容压缩为一个单独的 zip,这些 zip 将与小部件位于同一目录中。
我遇到的问题是我不知道如何删除初始文件夹,当您解压缩存档时,它需要所有文件和子文件夹都松散。
例如,如果我压缩 myFolder/index。html 和 myFolder/img/myImage.png
它应该像 index.html 和 img/my image.png
一样解压这对我来说非常有用,我每天必须将文件夹的内容压缩大约 50 次,用文件夹的名称重命名压缩文件并将它们复制到父文件夹中。
如果有人可以提供帮助,我愿意提供神秘奖品,我有大量的 Steam 钥匙!
谢谢
将
这应该可以帮助您入门。如果您不理解某个行为,请随时提问。
on open theFiles
repeat with x in theFiles
set _path to POSIX path of x
tell application "Finder"
if kind of x is "Folder" then
tell me to zipFolder(_path)
end if
end tell
end repeat
end open
on run
-- Handle the case where the script is launched without any dropped files
open (choose folder with multiple selections allowed)
end run
on zipFolder(theFolderPath)
do shell script "cd " & quoted form of theFolderPath & " && zip -r \"../$(basename $(pwd)).zip\" ./"
end zipFolder
这是 full applet 此外,您可能还想看看 LaunchBar、Alfred 和 Keyboard Maestro 等应用程序,它们有助于创建这样的操作。有一些用于存档的应用程序,例如 Archiver 和 Entropy,它们带有诸如此类的操作。
如果您想学习 applescript,可以考虑添加以下功能。
- 让小程序请求存档的名称,并使用它。
显示对话框处理程序,并将结果作为第二个参数传递给 zipFolder 处理程序
- 创建文件后在Finder中显示文件。
告诉 Finder 显示
- 将存档移动到特定目录以上传它,例如投递箱
告诉 Finder move/copy,或 bash 命令
mv
- 让小程序也处理文件。如果你想要它的任何行为。
其他人只能帮助你这么多,因为他们可能无法完全理解你所面临的困境,所以学习这一点会非常有用,而且很有趣。
对于任何感兴趣的人,这是我使用的最后一个脚本。此脚本获取任何选定的文件夹并从每个文件夹创建一个 zip 存档,将它们重命名为文件夹名称并且不包括 zip 中的根文件夹。这对于制作 Flashtalking HTML5 横幅特别有用。
on run {input, parameters}
if input is {} then -- no dropped items
tell application "Finder" to set input to selection as alias list
end if
repeat with x in input
set _path to POSIX path of x
tell application "Finder"
if kind of x is "Folder" then tell me to zipFolder(_path)
end tell
end repeat
end run
on zipFolder(theFolderPath)
do shell script "tDir=" & (quoted form of theFolderPath) & "; cd \"$tDir\"; aZip=\"../$(basename \"$tDir\").zip\"; if [ -e \"$aZip\" ]; then rm \"$aZip\"; fi; zip -r \"$aZip\" ./"
end zipFolder