Export Apple Photos to the Filesystem – Apple Script

I have never really used Apple Script, but recently had the desire to backup all my Apple Photos to my local NAS. I currently have all my photos organized in a Folder -> Album structure so pulled this Apple Script together together to get this done. Create a new Apple Script (*.scpt) and select the source Photos Folder and a location to save the files on your filesystem. Note: Slashes in the name case folders to be created 🙁

tell application "Photos"
	activate
	set folderList to name of every folder
	set selectedFolders to choose from list folderList with prompt "Select folders:" with multiple selections allowed
	set destination to POSIX path of (choose folder with prompt "Please select a backup location:")
	
	repeat with f in folders
		if selectedFolders contains name of f then
			my exportFolder(f, destination, name)
		end if
	end repeat
end tell

-- export a folder to a given destination
on exportFolder(tFolder, tPath, name)
	set folderName to tPath & "/" & name
	log folderName
	
	using terms from application "Photos"
		tell tFolder
			repeat with childAlbum in albums
				my exportAlbum(childAlbum, folderName)
			end repeat
			
			repeat with childFolder in folders
				set name to name of childFolder
				my exportFolder(childFolder, folderName, name)
			end repeat
		end tell
	end using terms from
end exportFolder

-- export an album to a given destination
on exportAlbum(tAlbum, tPath)
	set alName to name of tAlbum
	set albumName to tPath & "/" & alName
	my makeFolder(albumName)
	log albumName
	
	tell application "Photos"
		try
			with timeout of 30 * 60 seconds
				export (get media items of tAlbum) to (albumName as POSIX file) with using originals
			end timeout
		on error
			tell me to delay 5
			activate
			with timeout of 30 * 60 seconds
				export (get media items of tAlbum) to (albumName as POSIX file) with using originals
			end timeout
		end try
	end tell
end exportAlbum

on makeFolder(tPath)
	do shell script "mkdir -p " & quoted form of tPath
end makeFolder

https://gist.github.com/paschmann/536def178ea9dd96c22c2143cc2b212c