Содержимое папки в документе TextEdit - PullRequest
0 голосов
/ 06 июля 2019

Я нашел этот скрипт в https://macscripter.net/viewtopic.php?id=43410:

tell application "Finder"
    set thisFolder to choose folder with prompt "Please select the folder you wish to process." without invisibles
    set theseFiles to files of thisFolder as alias list
end tell

tell application "TextEdit"
    activate
    repeat with thisFile in theseFiles
        set newFilename to my getFilename(thisFile)
        set thisDoc to make new document
        tell thisDoc
            make new attachment with properties {file name:thisFile}
            set pathtofile to ((thisFolder as string) & newFilename & ".rtfd") as Unicode text
            save in file pathtofile
        end tell
        close front document saving no
    end repeat
end tell

on getFilename(thisFile)
    set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
    set theFilename to last text item of (thisFile as text)
    set AppleScript's text item delimiters to "."
    set newFilename to first text item of theFilename
    set AppleScript's text item delimiters to atid
    return newFilename
end getFilename

Этот скрипт выполняет один файл TextEdit на один файл исходной папки.

Как я могу изменить этот скрипт для создания одного файла TextEdit из всех файлов исходной папки? Файл результатов будет содержать все файлы папок.

Мне не нужен список имен файлов в документе TextEdit. Мне нужны все ФАЙЛЫ в документ TextEdit с вложениями (формат RTFD).

Ответы [ 2 ]

1 голос
/ 06 июля 2019

Признаюсь, мне не совсем понятно, что такое «вложение» в языке TextEdit или для чего оно может быть использовано, но если вам нужен только один файл со всеми этими вложениями, этодостаточно просто:

tell application "Finder"
    set thisFolder to choose folder with prompt "Please select the folder you wish to process." without invisibles
    set theFileName to name of thisFolder
    set theseFiles to files of thisFolder as alias list
end tell

tell application "TextEdit"
    activate
    set thisDoc to make new document
    set pathtofile to ((thisFolder as string) & theFileName & ".rtfd") as Unicode text
    tell thisDoc
        repeat with thisFile in theseFiles
            make new attachment with properties {file name:thisFile}
        end repeat
        save in file pathtofile
    end tell
    close front document saving no
end tell

РЕДАКТИРОВАТЬ

В комментариях приведена версия, которая применяет эту процедуру к подпапкам.Я немного очистил код (мне нравится использовать системные события лучше, чем Finder), но это тот же процесс.

set thisFolder to choose folder with prompt "Please select the folder you wish to process." without invisibles

tell application "System Events"
    set subFolders to folders of thisFolder
    repeat with aFolder in subFolders
        set folderName to name of aFolder
        set filePath to (POSIX path of thisFolder) & "/" & folderName & ".rtfd"
        set fileList to (POSIX path of every file of aFolder whose visible is true)
        tell application "TextEdit"
            activate
            set thisDoc to make new document
            tell thisDoc
                repeat with aFile in fileList
                    make new attachment with properties {file name:(POSIX file aFile) as alias}
                end repeat
                save in POSIX file filePath
            end tell
            close front document saving no
        end tell
    end repeat
end tell
return
0 голосов
/ 06 июля 2019

Я знаю, что вы можете сделать что-то похожее на то, что вы ищете в командной строке.

ls path_to_folder > path_to_export_file.txt

Пример:

ls ~/Desktop/ > ~/Desktop/export2.txt

Я почти уверен, что вы сможете интегрироватьэто в AppleScript, чтобы делать все остальное, что вам нужно.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...