1

Im facing a problem with AppleScript/Rsync.

I try to copy various folders from various drives to one HDD. The following shows a part of the Apple script which is more or less always the same part of code:

tell application "Finder"
    if (disk "MAC SSD X5" exists) then
        do shell script "rsync -azvp '/Volumes/MAC SSD X5' '/Volumes/Backup/MAC SSD X5' --progress --partial  --delete --backup  --backup-dir='/Volumes/Backup/Gelöschte\ Dateien'"
        
    end if
end tell

If I run this in Applescript it works. But uses rsync 2.6.9 which has less functions and less performance.

While if I run:

 rsync -azvp '/Volumes/MAC\ SSD\ X5' '/Volumes/Backup/MAC\ SSD\ X5' --progress --partial  --delete --backup  --backup-dir='/Volumes/Backup/Gelöschte\ Dateien'

directly in the terminal it uses rsync Version 3.2.3 from another folder.

I tried to remove the former Version (2.6.9) of rsync but I didn't succeed.

Also I tried to add

--rsync-path=/usr/bin/local/rsync 

in Applescript. But it still uses rsync 2.6.9. Also if I add the path of the rsync 2.6.9 in Terminal it will uses the new rsync (so the flag is not working either way).

Hope anyone can help me out with this issue.

Thanks in advance!

5
  • Not the case of your error, as nohillside already address it, however a comment about your code: The do shell script command is a part of Standard Additions in AppleScript. not Finder and as such should not be wrapped within the tell application "Finder" block as it actual throws a non-fatal error. Proper coding in this use case would be to use Finder to set a flag and a separate code block to act on the flag or use tell me to or tell current application to in front of the do shell script command. Nov 18, 2020 at 13:55
  • Setting a flag and a separate code block to act on the flag is the more proper way to go in this use case. Nov 18, 2020 at 13:56
  • Since I am a beginner could you give me examples on that "proper ways"? Thank You!
    – 8urg33
    Nov 19, 2020 at 15:08
  • As exists disk returns a boolean, I'd use System Events, (because it's faster than Finder), to set a boolean flag, e.g. diskExists by coding, e.g., tell application "System Events" to set diskExists to (exists disk "MAC SSD X5"). Now the value of diskExists is either true or false, so then to conditionally execute the do shell script command, I'd code, e.g., if diskExists then do shell script "..." -- This way commands that are not a part of an application's AppleScript dictionary are not being wrapped within its tell block. Nov 19, 2020 at 16:09
  • The bottom line is, even if a line of code throws a non-fatal error it shouldn't be used and it should be written so it doesn't throw an error unless it's a situation where a trappable error could occur or might be expected, in which case coding for proper error handling should be employed. Nov 19, 2020 at 16:09

1 Answer 1

4
  • Run type rsync in Terminal and take note of the path (I assume /usr/local/bin/rsync but this may be different in your case)

  • Call this version of rsync in your AppleScript

    do shell script "/usr/local/bin/rsync -azvp '/Volumes/MAC SSD X5' '/Volumes/Backup/MAC SSD X5' - ...
    

PS: --rsync-path is used to "specify the rsync to run on remote machine" which isn't relevant if you rsync between locally-mounted volumes.

1
  • Thank you so much! That worked for me!
    – 8urg33
    Nov 19, 2020 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .