папка zip с использованием appleScript - PullRequest
3 голосов
/ 05 февраля 2011

У меня есть этот appleScript, который берет выбранный элемент и заархивирует этот файл / папку и использует имя в качестве имени почтового индекса. Проблема, с которой я столкнулся, заключается в том, что, когда я распаковываю 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

Ответы [ 2 ]

3 голосов
/ 05 февраля 2011

Добавьте ключ -j к вашей команде zip.Другими словами, измените последнюю строку вашего скрипта перед «end tell» следующим образом:

do shell script "zip -jr " & zipFile & " " & itemPath

Это должно сказать команде zip «мусорный» путь к тому, что вы пытаетесь сжать, когда он делаетструктура каталогов для zip-файла.

2 голосов
/ 01 апреля 2012
tell application "Finder"
    set theItems to selection
    repeat with _a from 1 to (count of theItems)
        set theItem to (item _a of theItems) 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 repeat
end tell
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...