I know some, but not all, the aspects of this. Nobody said StackOverflow answers have to be complete so if anyone knows the bits I am missing they are welcome to add a complementary answer or edit mine.
Bear in mind that you can run bash
commands, and Python etc, from Applescript easily enough, so although OP asks for Applescript I presume they are happy enough with Applescript that calls bash
.
Let's say we want to grab the icon from the Notes app, reduce it, paste it onto the normal folder icon and set this new image to be the icon for a folder called Fred
on our desktop. So its icon will be:

So first we need to find the icon for Notes. We can do that by starting Notes and running:
ps -aef | grep Notes
501 22128 1 0 2:42am ?? 0:02.06 /System/Applications/Notes.app/Contents/MacOS/Notes
So now we know Notes lives in /System/Applications/Notes.app
Next we want to find its icon, so:
find /System/Applications/Notes.app -name "*.icns"
/System/Applications/Notes.app/Contents/Resources/AppIcon.icns
So now we know where its icons are, and we can extract the icon as a PNG to our Desktop with:
sips -s format png /System/Applications/Notes.app/Contents/Resources/AppIcon.icns --out ~/Desktop/notes.png
That looks like this:

I chose PNG format because, unlike JPEG, it supports transparency.
Now we can resize that and paste it onto the regular folder icon easily enough with PHP+gd (shipped with macOS) or with ImageMagick or with GIMP. I can do that if anyone else can help with the missing aspects.
Next, we can manually set the icon on a folder to the icon of another app and see what that results in. So, find an app in Finder, press ⌘I to bring up its info. Select the Fred
folder on your desktop and bring up its info the same way. Now click the icon at the top of the first info window to select it, copy with ⌘C and then click the icon at the top of the second info window and press ⌘V to paste it.
Now go into the folder with the new icon and you will find a file called Icon?
:
cd ~/Desktop/Fred
ls
Icon?
We can look inside that with xattr
:
xattr Icon*
com.apple.FinderInfo
com.apple.ResourceFork
And we can dump the resource fork with:
xattr -p com.apple.ResourceFork Icon*
I can see there are 8 PNG images in there.
So... the main missing link is how to get the images in that file...