How to RSYNC Instead Duplicate in AppleScript

I have a script where I choose a source folder and it pulls up in a window all the folders within it and lets me choose multiple folders to duplicate to another given location.

1.) How can I change the script to use rsync instead of duplicate

2.) How can I set the source folder instead of the choose option, each time I manually set the source folder with (set theFolder to “/Users/myersmi5/Desktop/”) I get the following error “Can’t get every folder of “/Users/myersmi5/Desktop””

set theFolder to choose folder
tell application "Finder"
	set theSourceFolder to theFolder
	set theFolderNames to get name of folders of theSourceFolder
	set theChosenNames to choose from list theFolderNames with prompt "Choose Which Folders to Backup" with multiple selections allowed
	if result is false then return
	set theDestinationFolder to choose folder
	repeat with thisName in theChosenNames
		duplicate folder thisName of theSourceFolder to theDestinationFolder with replacing
		
end repeat
end tell

Hi.

The Finder doesn’t understand POSIX paths, only its own references, aliases, and (on some older systems) HFS paths.

I’m not an expert on rsync, but based on some minimal research I did for a script of my own, the following is a direct translation of your script:

-- Use an alias to the source folder, which is understandable to the Finder and can be used to derive a POSIX path later.
set theFolder to (path to desktop)

tell application "Finder"
	activate -- Bring the Finder to the front to display the two dialogs.
	set theFolderNames to name of folders of theFolder
	set theChosenNames to (choose from list theFolderNames with prompt "Choose Which Folders to Backup" with multiple selections allowed)
	if (theChosenNames is false) then return
	set theDestinationFolder to (choose folder)
end tell

-- Copy or "update" each folder at the destination.
repeat with thisName in theChosenNames
	-- rsync options used here:
	-- -a: transfer entire contents, preserving most existing properties.
	-- -z: compress files during transfer. Nice over a slow connection, but otherwise better left out.
	-- --delete: if a copy of the folder already exists at the destination end, delete any items in it which aren't in the one at the source end.
	-- Quoted forms of the source and destination POSIX paths should be used in the shell script.
	-- The source path should not end with a slash, otherwise the folder's contents will be copied to the destination rather the folder itself.
	do shell script ("rsync -az --delete " & (quoted form of POSIX path of ((theFolder as text) & thisName)) & space & (quoted form of POSIX path of theDestinationFolder))
end repeat