0

我正在尝试编写脚本;

  1. 将文件夹拖到 Droplet
  2. 该脚本将“丢弃的文件夹”设置为源
  3. 项目清单
  4. 设置目标(不同的位置)
  5. rsync 每 5 分钟一次。

这是我的出发点。

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)

谢谢!

4

1 回答 1

0

该脚本将创建一个保持打开状态的 droplet,让您可以存储 rsync 命令列表并定期执行它们。将此代码复制/粘贴到脚本编辑器中,然后将其保存为Application,并单击“运行处理程序后保持打开”复选框。

  • 将文件夹拖放到应用程序图标上以设置 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
于 2019-09-13T18:50:19.830 回答