That script is meant to run in Automator. Open Automator, Add a new action "Run Applescript", paste that code, then run the action.
I think that key code is the "~" key. Not sure what pressing that 10000 times (which will take 3 hours the way this script is written) will do.
I'm not sure the following will work but it might as it forces Photos to download each original image from iCloud:
Install
osxphotos using
these instructions. This is a free command line tool for working with Photos which I've written.
Creating a temporary folder to export all your images to. For example, in your Pictures folder, "export" and run this command in Terminal.app
Bash:
osxphotos export ~/Pictures/export --download-missing
This will use osxphotos to export all your images (in this case to `~/Pictures/export` but you can substitute whichever path you want)
If your disk is formatted using APFS (standard for all Macs since Catalina, you can check in Disk Utility), then the export command won't take any extra space on your disk (APFS uses something called "copy-on-write" so a copied file doesn't take more space unless the copy is edited. If you have an older Mac that is using HFS+ and you don't have enough internal storage to store a copy of all photos, you could export to an external disk.