Thursday, June 4, 2020

#1 2020-03-31 01:12:06 pm

alitaliano
Member
Registered: 2010-10-12
Posts: 34
Website

set Icon to file/folder with Catalina "Bad CPU type in executable"

Hi,
Fortunately, Catalina didn't break many of my applescripts.
But I had found a solution to copy the icon of a folder to another, using a shell script and now it doesn't work anymore (error "Bad CPU type in executable").

Applescript:

tell me
   set AppleScript's text item delimiters to ""
               set src to MyPath_src
               set src to POSIX path of src
               set dst to POSIX path of MyPath_dest
               set srcicon_ to quoted form of (src & "Icon" & return)
               set dst_ to quoted form of dst
               
               set sh1 to "ditto --rsrc --extattr " & srcicon_ & " " & dst_ -- copy icon file to dst
               tell application "Finder" to set sh2 to (POSIX path of (folder of (path to me) as string))
               set sh2 to sh2 & "SetFile -a C " & dst_ -- set custom icon flag of dst
               do shell script (sh1 & " && " & sh2)

end tell

It now gives me the error "Bad CPU type in executable".
It seems that the "SetFile" executable is 32-bit, whereas Catalina is 64-bit only.

Is there another method to achieve this (copy icon from one folder to another) ?
Or is is possible to convert the "SetFile" executable in 64 bits easily ?

Thanks for your answer !

Offline

 

#2 2020-03-31 02:21:39 pm

alitaliano
Member
Registered: 2010-10-12
Posts: 34
Website

Re: set Icon to file/folder with Catalina "Bad CPU type in executable"

Hey,
I reply to myself as I've found the solution.

The original script was found on this page :
https://discussions.apple.com/thread/2057278

The command "SetFile" used is from Apple, so I just installed the new command line tools :
https://osxdaily.com/2014/02/12/install … -mac-os-x/

And the script now works using the new "SetFile" command in 64-bits (I guess).

Offline

 

#3 2020-03-31 02:27:45 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4395

Re: set Icon to file/folder with Catalina "Bad CPU type in executable"

I'm using the code below to attach the contents of a picture file as icon of a given folder.

Applescript:

use framework "Foundation"
use scripting additions

set sourcePath to choose file of type {"icns", "jpeg", "jpg", "png", "tiff"}
set target to (path to desktop as text) & "nouveau"

my setIcon(target, sourcePath)

to setIcon(fileRef, imagePath)
   set iconImage to current application's NSImage's alloc's initWithContentsOfFile:(POSIX path of imagePath)
   current application's NSWorkspace's sharedWorkspace's setIcon:iconImage forFile:(POSIX path of fileRef) options:0
end setIcon

Alas, it fails if sourcePath points to the file "Icon" & return stored in an other folder.

Maybe somebody will be able to edit it.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 31 mars 2020  22:26:23

Offline

 

#4 2020-03-31 05:15:27 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6369

Re: set Icon to file/folder with Catalina "Bad CPU type in executable"

Yvan Koenig wrote:

Maybe somebody will be able to edit it.



I don't think so. You shouldn't read the icon file directly -- instead, use this on the file showing the image:

Applescript:

set theImage to current application's NSWorkspace's sharedWorkspace's iconForFile:posixPath


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2020-04-01 01:58:02 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4395

Re: set Icon to file/folder with Catalina "Bad CPU type in executable"

Thank's Shane

When I tested I was afraid because the icon didn't appear immediately on the target folder but it did a  few seconds later.

It behaves faster when the icon isn't borrowed from a folder but from a file.

Applescript:

use framework "Foundation"
use scripting additions

-- set sourcePath to (path to desktop as text) & "beurk.txt" -- a text file with an icon
set sourcePath to (path to desktop as text) & "beurk" -- a folder
set target to (path to desktop as text) & "nouveau"

my setIcon(target, sourcePath)

to setIcon(targetPath, sourcePath) -- sourcePath may point to a file or a folder
   set iconImage to current application's NSWorkspace's sharedWorkspace's iconForFile:(POSIX path of sourcePath)
   current application's NSWorkspace's sharedWorkspace's setIcon:iconImage forFile:(POSIX path of targetPath) options:0
end setIcon

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 1 avril 2020  09:57:53

Offline

 

#6 2020-04-01 06:18:13 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 485

Re: set Icon to file/folder with Catalina "Bad CPU type in executable"

Right now I use the following script to change AppleScript app icons, and it seems to work fine. I obtained the ASObjC portion from another thread (which I can't find now), and I wondered if there's a better way to do the ASObjC part. Thanks.

Applescript:

use framework "Foundation"
use scripting additions

set theFile to POSIX path of (choose file)

set theIcon to POSIX path of (choose file of type {"icns", "jpeg", "jpg", "png", "tiff"})

set ws to current application's NSWorkspace's sharedWorkspace()
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:theIcon
ws's setIcon:theImage forFile:theFile options:0

Last edited by peavine (2020-04-01 06:26:10 pm)


2018 Mac mini - macOS Catalina

Offline

 

#7 2020-04-01 10:10:51 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6369

Re: set Icon to file/folder with Catalina "Bad CPU type in executable"

peavine wrote:

I wondered if there's a better way to do the ASObjC part.



That's essentially the same code as Yvan provided above.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)