Matt Kelly Matt Kelly - 1 year ago 150
AppleScript Question

Applescript - rsync to NAS Drive

I've checked out a few questions but none have helped so far.

I have an AppleScript backing up my RAW files from one HDD to another, and I'd like to include a NAS drive in that process. I'm using

to copy the files, but I'm having trouble referencing the NAS Drive in my

I have a line of code referencing the NAS Drive as a test which is working:

do shell script "open 'smb://NASDrive/Matt RAW Backup/Backups'"

However, the following line of code isn't working:

do shell script "rsync -a '/Users/Matt/Desktop/Test Folder/' '/Volumes/NASDrive/Matt RAW Backup/Backups' --delete"

('NASDrive' is the name of the NAS Drive, and 'Matt RAW Backup' is the share name)

I get the following error in the 'Result' bar:

error "ssh: Could not resolve hostname smb: nodename nor servname provided, or not known
rsync: connection unexpectedly closed (0 bytes received so far) [sender]

rsync error: unexplained error (code 255) at /BuildRoot/Library/Caches/ [sender=2.6.9]" number 255

Does anyone know why the
command is failing, but the
command with the same reference to the folder is working?

Answer Source

It's probably a timing issue.

I recommend to use the AppleScript mount volume command and wait until the disk appears in /Volumes

You need to replace server.local with the server name of your NAS.

set diskName to "NASDrive"
    mount volume "smb://server.local/" & diskName
    repeat until diskName is in (do shell script "ls /Volumes")
        delay 0.2
    end repeat
    do shell script "rsync -a '/Users/Matt/Desktop/Test Folder/' '/Volumes/NASDrive/Matt RAW Backup/Backups' --delete"
on error e
    display dialog "An error occurred: " & e
end try
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download