rsync apple script syntax error - help please :]

Hi all


Im having difficulty with my rsync syntax.

I want to write a script that backs up folders from my 'home' folder.


The rsync works perfectly in terminal.

I just cant get it to work in applescript.


I get error - Expected “"” but found unknown token.

Id really really appreciate it if someone could help me out here and show me whats wrong with the syntax.


tell application "Finder"


activate


do shell script "rsync -ruv --exclude-from=/Volumes/John\'s\ Stuff/john/Rsync/Exclude\ from\ Media\ Storage.txt /Volumes/John\'s\ Stuff/john /Volumes/Media\ Storage\ 1 "

end tell


display dialog "Backup complete, Do you want to eject the disk?"


if result = {button returned:"Ok"} then

try

do shell script "diskutil eject /Volumes/Media*Storage*1"

display dialog "Successfully ejected the disk." buttons {"Close"} default button "Close"


on error

display dialog "Unable to eject the disk." buttons {"Close"} default button "Close"

end try


else if result = {button returned:"Cancel"} then

end if

end

OS X Yosemite (10.10.3), null

Posted on Jun 14, 2015 10:06 AM

3 replies

Jun 14, 2015 10:41 AM in response to Community User

I had trouble compiling what you pasted, there appears to be tabs or some other invisible character before the indented lines. I cleared them out & then double escaped the command

I believe the 'do shell script' command requires you to double escape (the shell expands one backslash, the do shell script expands the other).



tell application "Finder"


activate

do shell script "rsync -ruv --exclude-from=/Volumes/John\\'s\\ Stuff/john/Rsync/Exclude\\from\\Media\\ Storage.txt /Volumes/John\\'s\\ Stuff/john /Volumes/Media\\ Storage\\ 1"

end tell


display dialog "Backup complete, Do you want to eject the disk?"

if result = {button returned:"Ok"} then

try

do shell script "diskutil eject /Volumes/Media\\ Storage\\ 1"

display dialog "Successfully ejected the disk." buttons {"Close"} default button "Close"

on error

display dialog "Unable to eject the disk." buttons {"Close"} default button "Close"

end try

else if result = {button returned:"Cancel"} then

end if


I haven't tested it with rsync, so see if it works for you.

I also made diskutil eject the disk name without the wildcards - you need to double escape that too.



Personally I find it easier to convert to quoted variables and then smash them into a string via '&'…


set source to quoted form of POSIX path of "/Volumes/John's Stuff/john"

set dest to quoted form of POSIX path of "/Volumes/Media Storage 1"

set exclude to quoted form of POSIX path of "/Volumes/John's Stuff/john/Rsync/Exclude from Media Storage.txt"


tell application "Finder"


activate

do shell script "rsync -ruv --exclude-from=" & exclude & " " & source & " " & dest

end tell


display dialog "Backup complete, Do you want to eject the disk?"


if result = {button returned:"Ok"} then

try

do shell script "diskutil eject " & dest

display dialog "Successfully ejected the disk." buttons {"Close"} default button "Close"

on error

display dialog "Unable to eject the disk." buttons {"Close"} default button "Close"

end try

else if result = {button returned:"Cancel"} then

end if


P.S.

See this if you want to automate fixing the broken indenting that this forum does to Applescripts.

Bookmarklet to fix AppleScript pasting on discussions.apple.com

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

rsync apple script syntax error - help please :]

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.