As you ask to copy the custom icon applied to a given folder to an other folder you may use :
# Use a CLI available from : http://www.bluem.net/en/mac/cliclick/
# Edit these three instructions to fit your needs
set p2d to path to desktop as text
set theSource to (p2d & "source:") as alias
set theTarget to (p2d & "target:") as alias
tell application "Finder"
select theSource
tell me to set the clipboard to "" # an old habit
tell application "System Events" to tell process "Finder"
set frontmost to true
keystroke "i" using {command down} # open infos window
set infoWindow to window 1 --> "Infos sur source"
tell infoWindow
--class of UI elements -->{scroll area, button, button, button, image, static text}
tell scroll area 1
class of UI elements --> {image, static text, static text, static text, static text, scroll area, UI element, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, checkbox, checkbox, UI element, static text, static text, static text, UI element, static text, text field, checkbox, UI element, static text, scroll area, UI element, static text, UI element, static text, static text, scroll area, button, button, menu button, checkbox, scroll bar}
set {xLeft, yTop} to position of image 1
set {w, h} to its size of image 1
tell me to do shell script "/Users/admin/bin/cliclick c:" & xLeft + w div 2 & "," & yTop + h div 2
delay 0.1
keystroke "c" using {command down}
end tell
end tell
end tell
select theTarget
tell application "System Events" to tell process "Finder"
set frontmost to true
keystroke "i" using {command down} # open infos window
set infoWindow to window 1 --> "Infos sur target"
tell infoWindow
--class of UI elements -->{scroll area, button, button, button, image, static text}
tell scroll area 1
class of UI elements --> {image, static text, static text, static text, static text, scroll area, UI element, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, checkbox, checkbox, UI element, static text, static text, static text, UI element, static text, text field, checkbox, UI element, static text, scroll area, UI element, static text, UI element, static text, static text, scroll area, button, button, menu button, checkbox, scroll bar}
set {xLeft, yTop} to position of image 1
set {w, h} to its size of image 1
tell me to do shell script "/Users/admin/bin/cliclick c:" & xLeft + w div 2 & "," & yTop + h div 2
delay 0.1
keystroke "v" using {command down}
end tell
end tell
end tell
end tell # Finder
CAUTION: the custom icon will disappear if you apply the command update to the target folder.
Just for info, the name of the custom icon file is not “Icon” but it’s “Icon” & return
I tried to run:
tell application "Finder"
set aFold to choose folder "Select folder to copy icon"
set bFold to choose folder "Select folder to transfer to"
set aFold to aFold as string
set file1 to aFold & ".DS_Store"
set file2 to aFold & "Icon" & return
try
duplicate alias file1 to bFold # Here ".DS_Store" is not available
end try
duplicate alias file2 to bFold
end tell
The file whose name is “Icon” & return is correctly duplicated but the Finder doesn’t use it as icon.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 31 juillet 2019 16:57:57