apple-mac-os:macos-ventura:automatic-synchronization-of-files-and-directories-on-macos
Различия
Показаны различия между двумя версиями страницы.
Следующая версия | Предыдущая версия | ||
apple-mac-os:macos-ventura:automatic-synchronization-of-files-and-directories-on-macos [09.01.2023 12:46] – создано Алексей Максимов | apple-mac-os:macos-ventura:automatic-synchronization-of-files-and-directories-on-macos [08.11.2023 20:41] (текущий) – Виталий Якоб | ||
---|---|---|---|
Строка 2: | Строка 2: | ||
{{: | {{: | ||
+ | В данном примере выполняется синхронизация перечисленных каталогов в ~/ | ||
- | Сохраним **AppleScript** скрипт в расположении '' | + | Сохраним **AppleScript** скрипт в расположении '' |
- | <code applescript Sync folder to removable disk.scpt> | + | <code applescript Sync folder to removable disk.scpt> |
+ | on adding folder items to this_folder after receiving MountedVolumes | ||
+ | set SyncRootFolder to " | ||
| | ||
tell application " | tell application " | ||
| | ||
set RemovableDiskName to " | set RemovableDiskName to " | ||
- | if (local volume of MountedVolume) and (name of MountedVolume is RemovableDiskName) then | + | if (local volume of disk MountedVolume) and (name of disk MountedVolume is RemovableDiskName) then |
--Имена синхронизируемых каталогов | --Имена синхронизируемых каталогов | ||
set SyncFolders to {¬ | set SyncFolders to {¬ | ||
" | " | ||
" | " | ||
- | " | + | " |
+ | " | ||
repeat with SyncFolder in SyncFolders | repeat with SyncFolder in SyncFolders | ||
- | set SourcePath to quoted form of ("/ | + | |
- | set DestinationPath to quoted form of ("/ | + | my StartSync(SyncRootFolder, SyncFolder, RemovableDiskName) |
- | try | + | |
- | set StartSync to do shell script " | + | |
- | (* | + | |
- | -a -- Режим архивирования, | + | |
- | -u -- пропускает более новые файлы в месте назначения. | + | |
- | --delete -- удаляет файлы в месте назначения, | + | |
- | *) | + | |
- | --Пауза для последовательного показа уведомлений | + | |
- | delay 1 | + | |
- | if StartSync = "" | + | |
- | | + | |
- | " | + | |
- | end if | + | |
- | --Ошибки | + | |
- | on error errorMessage number errorNumber | + | |
- | --log ("(line #" & StartSync & ") errorMessage: | + | |
- | if errorNumber = 12 then | + | |
- | | + | |
- | space & " | + | |
- | сихронизировать каталог" | + | |
- | else if errorNumber = 23 then | + | |
- | | + | |
- | "не существует." | + | |
- | else | + | |
- | | + | |
- | end if | + | |
- | end try | + | |
end repeat | end repeat | ||
- | --Раскомментировать если необходимо отключение | + | --Раскомментировать, если необходимо отключать |
- | (* | + | |
- | delay 5 | + | |
- | try | + | |
- | tell application " | + | |
- | 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 StartSync(SyncRootFolder, | ||
+ | | ||
+ | set SourcePath to quoted form of (POSIX path of (path to documents folder as text) & SyncRootFolder & "/" | ||
+ | | ||
+ | tell application " | ||
+ | try | ||
+ | do shell script "rsync -au --delete" | ||
+ | delay 1 | ||
+ | display notification " | ||
+ | " | ||
+ | on error ErrorMessage | ||
+ | set ErrorMessage to do shell script " | ||
+ | display dialog " | ||
+ | | ||
+ | end try | ||
+ | end StartSync | ||
+ | |||
+ | --Обработчик размонтрования накопителя | ||
+ | on UnmountDisk(RemovableDiskName) | ||
+ | delay 5 | ||
+ | tell application " | ||
+ | end UnmountDisk | ||
+ | </ | ||
Чтобы установить скрипт, | Чтобы установить скрипт, | ||
Строка 69: | Строка 66: | ||
{{ : | {{ : | ||
- | |||
- | Для синхронизации каталогов по заданному расписанию, | ||
Строка 77: | Строка 72: | ||
^ Версия ОС ^ | ^ Версия ОС ^ | ||
| Apple macOS Ventura (13.0) | | Apple macOS Ventura (13.0) | ||
+ | | Apple macOS Sonoma (14.0) | ||
---- | ---- |
apple-mac-os/macos-ventura/automatic-synchronization-of-files-and-directories-on-macos.txt · Последнее изменение: 08.11.2023 20:41 — Виталий Якоб