【问题标题】:Folder Backup every 5 minutes (Applescript - Droplet)每 5 分钟备份一次文件夹 (Applescript - Droplet)
【发布时间】:2019-09-14 08:21:28
【问题描述】:
我正在尝试编写脚本;
- 将文件夹拖到 Droplet
- 脚本将“丢弃的文件夹”设置为源
- 列表项
- 设置目标(不同位置)
- 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)
谢谢!
【问题讨论】:
标签:
applescript
automator
droplet
【解决方案1】:
此脚本将创建一个保持打开状态的 droplet,让您可以存储 rsync 命令列表并定期执行它们。将此代码复制/粘贴到脚本编辑器中,然后将其另存为 Application,并选中 '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