apple-mac-os:macos-monterey:automate-torrent-downloads-on-macos
Различия
Показаны различия между двумя версиями страницы.
| Предыдущая версия справа и слеваПредыдущая версияСледующая версия | Предыдущая версия | ||
| apple-mac-os:macos-monterey:automate-torrent-downloads-on-macos [28.10.2022 08:54] – Виталий Якоб | apple-mac-os:macos-monterey:automate-torrent-downloads-on-macos [08.11.2023 17:36] (текущий) – Виталий Якоб | ||
|---|---|---|---|
| Строка 38: | Строка 38: | ||
| В итоге получился рабочий вариант, | В итоге получился рабочий вариант, | ||
| - | Сохраняем скрипт в каталоге '' | + | Сохраняем скрипт в каталоге '' |
| - | < | + | < |
| + | --Глобальная переменная, передаём расширение | ||
| property FileExt : " | property FileExt : " | ||
| + | --Выполняется при любом добавлении файла в каталог | ||
| on adding folder items to this_folder after receiving added_items | on adding folder items to this_folder after receiving added_items | ||
| repeat with torrentFile in added_items | repeat with torrentFile in added_items | ||
| - | tell application "Finder" | + | tell application "System Events" |
| - | if the name extension of the torrentFile is in the FileExt then | + | --если добавленный файл имеет расширение torrent, процесс запускается |
| - | (* | + | if the name extension of the torrentFile is equal to FileExt then |
| - | Параметры переменных подключения к серверу | + | --Параметры переменных подключения к серверу |
| - | Пользователь, | + | --Пользователь, |
| - | *) | + | |
| set transmissionuser to " | set transmissionuser to " | ||
| set transmissionpass to " | set transmissionpass to " | ||
| Строка 58: | Строка 58: | ||
| set transmissionurl to " | set transmissionurl to " | ||
| set rpcurl to transmissionurl & "/ | set rpcurl to transmissionurl & "/ | ||
| - | --Проверяем доступность | + | --Если сервер доступен, отправляем файл |
| - | try | + | if (my CheckServer(transmissionhost, |
| - | do shell script "nc -z " & transmissionhost & space & transmissionport | + | then my SendTorrent(torrentFile, rpcurl, transmissionauth) |
| - | try | + | |
| - | set metainfo to do shell script " | + | |
| - | set sessionid to do shell script "curl --silent " & rpcurl & " --anyauth --user " & transmissionauth & ¬ | + | |
| - | " | + | |
| - | set json to " | + | |
| - | set answer to do shell script "curl --silent --anyauth --user " & transmissionauth & space & rpcurl & " --header " & ¬ | + | |
| - | quoted form of (sessionid) & " -d " & quoted form of (json) & " | sed ' | + | |
| - | if answer = " | + | |
| - | -- Показ уведомления об успешной отправке | + | |
| - | display notification (name of torrentFile as text) with title " | + | |
| - | --Удаление обработанного .torrent | + | |
| - | --delete torrentFile -- удаление в корзину | + | |
| - | do shell script "rm -f " & quoted form of (POSIX path of (torrentFile)) | + | |
| - | else | + | |
| - | -- Сообщение об ошибке отправки .torrent файла, исчезает через 10 сек | + | |
| - | set errMsg to do shell script "echo " & quoted form of (answer) & " | sed ' | + | |
| - | display dialog " | + | |
| - | + | ||
| - | Ответ сервера: | + | |
| - | end if | + | |
| - | end try | + | |
| - | on error | + | |
| - | -- Сообщение об ошибке связи с сервером, | + | |
| - | display dialog " | + | |
| - | " | + | |
| - | end try | + | |
| end if | end if | ||
| end tell | end tell | ||
| end repeat | end repeat | ||
| - | end adding folder items to</ | + | end adding folder items to |
| + | |||
| + | --Проверка доступности сервера | ||
| + | on CheckServer(thost, | ||
| + | try | ||
| + | do shell script "nc -z" & space & thost & space & tport | ||
| + | return true | ||
| + | on error | ||
| + | display dialog " | ||
| + | " | ||
| + | end try | ||
| + | end CheckServer | ||
| + | |||
| + | --Отправка torrent файла в формате base64 | ||
| + | on SendTorrent(torrentFile, | ||
| + | set metainfo to do shell script " | ||
| + | set sessionid to do shell script "curl --silent " & rpcurl & " --anyauth --user " & transmissionauth & ¬ | ||
| + | " | sed ' | ||
| + | set json to " | ||
| + | set answer to do shell script "curl --silent --anyauth --user " & transmissionauth & space & rpcurl & " --header " & ¬ | ||
| + | quoted form of (sessionid) & " -d " & quoted form of (json) & " | sed ' | ||
| + | if answer is equal to " | ||
| + | my SuccessAction(torrentFile) | ||
| + | else | ||
| + | my ErrorAction(answer, | ||
| + | end if | ||
| + | end SendTorrent | ||
| + | |||
| + | --В случае успеха отправки | ||
| + | on SuccessAction(torrentFile) | ||
| + | -- Показ уведомления об успешной отправке | ||
| + | display notification name of (info for (torrentFile as alias)) with title " | ||
| + | --Удаление обработанного .torrent файла | ||
| + | --delete torrentFile -- удаление в корзину | ||
| + | do shell script "rm -f " & quoted form of (POSIX path of (torrentFile)) | ||
| + | end SuccessAction | ||
| + | |||
| + | --В случае неудачи отправки | ||
| + | on ErrorAction(answer, | ||
| + | -- Сообщение об ошибке отправки .torrent файла, исчезает через 10 сек | ||
| + | set errMsg to do shell script "echo " & quoted form of (answer) & " | sed ' | ||
| + | display dialog " | ||
| + | errMsg with title " | ||
| + | end ErrorAction | ||
| + | </ | ||
| Для установки скрипта вызываем контекстное меню на каталоге: | Для установки скрипта вызываем контекстное меню на каталоге: | ||
| Строка 111: | Строка 129: | ||
| | Apple macOS Monterey (12.0) | | Apple macOS Monterey (12.0) | ||
| | Apple macOS Ventura (13.0) | | Apple macOS Ventura (13.0) | ||
| + | | Apple macOS Sonoma (14.0) | ||
| ---- | ---- | ||
apple-mac-os/macos-monterey/automate-torrent-downloads-on-macos.1666947284.txt.gz · Последнее изменение: — Виталий Якоб