on run {input}
set {countInp, nameList, s} to {count input, "", 0}
tell application "System Events" to set sourcePath to POSIX path of container of item 1 of input
if countInp = 1 then
set dial to "rsync " & quoted form of POSIX path of item 1 of input & " to:"
else
set dial to "rsync " & quoted form of POSIX path of item 1 of input & " + " & countInp - 1 & " files more to:"
end if
activate
set setDest to choose folder with prompt dial
tell application "System Events" to repeat with x in input
if displayed name of x contains "/" then
with timeout of 3600 seconds
display alert quoted form of (displayed name of x as string) & " not synced." message quoted form of "/" & " not allowed in file name." buttons {"Cancel", "Skip"} cancel button 1 as critical
end timeout
else
set nameList to nameList & quoted form of (name of x as string) & space
try
set s to my getSize(s, x)
on error erstrg
display alert erstrg as critical
end try
end if
end repeat
if nameList = "" then return
if s < 10000 then
appShell(sourcePath, nameList, setDest)
else
term(sourcePath, nameList, setDest)
end if
end run
on getSize(s, x)
s + (word 1 of (do shell script "du -k " & quoted form of (POSIX path of x as string))) / 976.5625
end getSize
on appShell(sourcePath, nameList, setDest)
try
do shell script "cd " & quoted form of sourcePath & " ; rsync -rltD --exclude=.DS_Store " & nameList & quoted form of POSIX path of setDest & "&&afplay /System/Library/Sounds/Ping.aiff -v .2"
on error
try
do shell script "cd " & quoted form of sourcePath & " ; rsync -rltD --exclude=.DS_Store " & nameList & quoted form of POSIX path of setDest & "&&afplay /System/Library/Sounds/Ping.aiff -v .2" with administrator privileges
on error errstrg number errnmb
if errnmb = -128 then error number -128
display alert errstrg as critical
end try
end try
try
display notification nameList with title "rsync:"
end try
tell application "Finder"
open setDest
activate
end tell
end appShell
on term(sourcePath, nameList, setDest)
tell application "Terminal"
activate
do script "cd " & quoted form of sourcePath & " ; rsync -vrltD --progress --stats --exclude=.DS_Store " & nameList & quoted form of POSIX path of setDest & "&&afplay /System/Library/Sounds/Ping.aiff -v .2"
end tell
end term