0

I've been working on a simple automator backup utility using applescript and rsync and got everything working apart from 1 more issue, when starting the script, I want to be able to select multiple hard drives to back up (which works), afterwards, I allow selection of only 1 backup drive, the problem is, I want all the selected drives to reside in their own folder on the backup drive (see attached screenshots), but am a bit lost on how I should do this (I am new to applescript and rsync and only got this far by doing a lot of research, but am now stuck)

This is the code I have, all the drive paths are in the 'sources' variable, which i iterate over in a for loop.

    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

Any help would be greatly appreciated (and if you have remarks regarding the code, please feel free to enlighten me, as I am still a rookie at applescript)

Thanks in advance!

Sources to backup (multiple selections allowed

Destination drive (only 1 selection allowed)

1 Answers1

0

Fixed this using a little trick:

The path returned from choose folder and converted to POSIX path has an ending forward slash, e.g. Volumes/Data Drive X/

However, when not providing this last slash, a folder with the same name is expected at the path destination (and created if not available), which is exactly what i needed.

To remove the last slash from the path, I simply added the following after converting the alias to a POSIX path: set source to text 1 thru -2 of source

so that Volumes/Data Drive X/ becomes Volumes/Data Drive X

Hope this helps anyone with the same issue! :)