File Copy "fail?" [CP]

A script that builds a DMG, and is supposed to change the desktop icon… (which DID work before)

 let dmgVOL  = "/Volumes/\(vol)"
let iconVOL = "\(dmgVOL)/.VolumeIcon.icns"
log("\t\tAdd Custom Desktop Icon \(part)",false)
                //
 r = execute("cp -R -P '\(custom_icon)' '\(iconVOL)'")
 r = execute("SetFile -a C '\(iconVOL)'")
r = execute("SetFile -a C '\(dmgVOL)'")

If there is a period (ie. hidden) on VolumeIcon.icns it does NOT seem to copy the file ( I have macOS set to show hidden files) but the AppleScript the arranges things does not barf when it is told to set the finder location.

But if I REMOVE the “.” it DOES copy the file into the DMG, but of course then the AS does barf.

So the first method “looks” like it is working, but the desktop icon does not change

oh, and the return value (r) are blank in all cases

IIRC, SetFile is a decade depreciated, and using AppleScript to set the icon at some point in the process is necessary?

Maybe you could bundle and use fileicon instead?

Otherwise, I’m not sure theres enough information to follow this: vol, part are not defined here.

I also thought log() was a math function(?) and I haven’t seen execute() in swift. I also rarely use swift, which might be why.

You are correct, SETFILE is deprecated, but it seems to be the only command in any article about setting the bundle icon.

Yes, AS is not required to set the desktop icon , but is to set the internal background (where I do not have an issue).

But regardless of Setfile, it is the COPY (CP) command that the question concerns.

FYI. Log is my function to write to a log file, and execute is a wrapper around SHELL

iconVOL for example resolves to '/Volumes/myDMG/VolumeIcon.icns'
and custom_icon is the path to the .ICNS file to be used

I always used ditto not CP

honestly don’t normally see CP in a title like it is here, so my first instinct was to panic. :smiley:

Take a look at the fileicon source. It’s well commented, and will help with what you are doing. GitHub - mklement0/fileicon: macOS CLI for managing custom icons for files and folders

ok, let me present the question in a differnt manner

cp -R -P 'test.icns' '/Volumes/myDMG/.VolumeIcon.icns'
–or–
ditto 'test.icns' '/Volumes/myDMG/.VolumeIcon.icns'

DO NOT COPY THE FILE (other files in the script seem to work)

HOWEVER
both

cp -R -P 'test.icns' '/Volumes/myDMG/stuff'
–and–
ditto 'test.icns' '/Volumes/myDMG/stuff'

DO WORK…
leading me to believe that for this purpose there is no difference between CP or DITTO, but for some unknown reason is has to do with the file name

Note : if i use .stuff (dot stuff) it does WORK, and the file shows up hidden just like it should

but .VolumeIcon.icns will NOT work

Perchance does ‘/Volumes/myDMG/.VolumeIcon.icns’ already exist ?
Manually doing the CP doesnt show any error message ?
Just never seen cp & ditto fail silently

Turns out (pointed out by Norm) that perhaps Finder was at fault…

Doing a “ls -a” showed the file was in fact being copied, but for reasons still unknown was NOT being properly attached to show as the desktop icon