每 5 分钟备份一次文件夹(Applescript - Droplet)

Folder Backup every 5 minutes (Applescript - Droplet)

我正在尝试编写脚本;

  1. 将文件夹拖到 droplet
  2. 脚本将 "dropped folder" 设置为源
  3. 列表项
  4. 设置目标(不同位置)
  5. 每 5 分钟 rsync。

这是我的起点。

set source to "Dropped_Folder"
set destFolder to "/Users/xxx/Documents"
do shell script "/usr/bin/rsync -a  " & (quoted form of source) & " " & (quoted form of destFolder)

谢谢!

此脚本将创建一个保持打开状态的 droplet,让您可以存储 rsync 命令列表并定期执行它们。 Copy/paste 将此代码放入脚本编辑器,然后将其另存为 A​​pplication,并选中 'Stay open after run handler' 复选框。

  • 将文件夹拖放到应用程序图标上以设置 rsync
  • 双击应用程序图标或单击停靠图标以从内部列表中删除 rsync 命令。

该应用程序将每 execInterval 秒执行一次所有命令,直到您退出它,并在您重新启动它时恢复执行(除非您重新保存或重新编译该应用程序,这会清除其持久性 属性 存储) .

property rsyncCommandList : {}
property execInterval : 300 -- 300 seconds is 5 minutes

on run
    if (count of rsyncCommandList) = 0 then
        display alert "No rsync commands set up. Drop a folder on the application icon to set up an rsync command." as informational
    end if
end run

on reopen
    if (count of rsyncCommandList) > 0 then
        set deletableCommandList to (choose from list rsyncCommandList with prompt "Remove unwanted rsync commands" OK button name "Remove selected" with multiple selections allowed and empty selection allowed)
        set revisedList to {}
        repeat with thisItem in rsyncCommandList
            if (get thisItem) is not in deletableCommandList then
                copy thisItem to end of revisedList
            end if
        end repeat
        set rsyncCommandList to revisedList
    end if
end reopen

on open theseItems
    repeat with thisItem in theseItems
        set source to POSIX path of thisItem
        set destination to POSIX path of (choose folder "Choose a destination folder for bacups of disk item '" & thisItem & "'")
        set rsyncString to "/usr/bin/rsync -a " & (quoted form of source) & " " & (quoted form of destination)
        copy rsyncString to end of rsyncCommandList
    end repeat
end open

on idle
    repeat with thisCommand in rsyncCommandList
        do shell script thisCommand & " &> /dev/null"
    end repeat
    return execInterval
end idle