【问题标题】:Applescript: Rsync multiple drives to 1 organised driveApplescript:将多个驱动器同步到 1 个有组织的驱动器
【发布时间】:2017-12-06 18:59:35
【问题描述】:

我一直在使用 applescript 和 rsync 开发一个简单的自动备份实用程序,除了另外 1 个问题外,一切正常,在启动脚本时,我希望能够选择多个硬盘驱动器进行备份(可行) ,之后,我只允许选择 1 个备份驱动器,问题是,我希望所有选定的驱动器都驻留在备份驱动器上它们自己的文件夹中(请参阅随附的屏幕截图),但是我应该如何做到这一点有点迷失(我是 applescript 和 rsync 的新手,通过大量研究才走到这一步,但现在卡住了)

这是我的代码,所有驱动路径都在“源”变量中,我在 for 循环中对其进行迭代。

    set sources to (choose folder with prompt "Select drives to back up" default location "Volumes" with multiple selections allowed)
    set destination to (the POSIX path of (choose folder with prompt "Select destination volume" default location "Volumes"))

    #for loop iterating all sources to backup
    repeat with aliasPath in sources

        set source to the POSIX path of aliasPath

        set sciptsFinished to false

        tell application "Terminal"
            if not (exists window 1) then reopen
            activate
            do script "rsync --dry-run --archive -v --progress --exclude=\".*\"  --delete --delete-during --stats --human-readable --human-readable " & quoted form of source & " " & quoted form of destination in window 1

            delay 5 #give terminal time to activate
            repeat while (window 1 is busy)
                delay 1
            end repeat

            do script "osascript -e 'display notification \"RSYNC file changes calculated.\" with title \"RSYNC Backup\"'" in window 1

            #mark scripts completed
            set scriptsFinished to true

        end tell

        #wait for scripts to finish before proceeding
        repeat while (scriptsFinished is false)
            delay 2
        end repeat

任何帮助将不胜感激(如果您对代码有意见,请随时启发我,因为我仍然是 applescript 的新手)

提前致谢!

Sources to backup (multiple selections allowed

Destination drive (only 1 selection allowed)

【问题讨论】:

    标签: applescript backup rsync organized


    【解决方案1】:

    用一个小技巧解决了这个问题:

    从选择文件夹返回并转换为 POSIX 路径的路径有一个结束正斜杠,例如 Volumes/Data Drive X/

    但是,当不提供最后一个斜杠时,路径目标处应该有一个同名的文件夹(如果不可用,则创建),这正​​是我所需要的。

    要从路径中删除最后一个斜杠,我只是在将别名转换为 POSIX 路径后添加了以下内容: set source to text 1 thru -2 of source

    这样 Volumes/Data Drive X/ 变成 Volumes/Data Drive X

    希望这对遇到同样问题的人有所帮助! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      相关资源
      最近更新 更多