3

I am trying to write the Code in Python to Change the Icon of a Mac OS X folder using just the Python Script (Without XCODE or any other API). The procedure is that I have a icon.icns file , I need to change the folder icon to the icon.icns file using the python script.

  • Have you found a solution to this yet? I'm also curious about it – Yasin Mar 28 '16 at 06:54
  • Let we have a icon.icns file: Read the com.apple.ResourceFork extended attribute from the icon file Set the com.apple.FinderInfo extended attribute with folder icon flag Create a Icon file (name: Icon\r) inside the target folder Set extended attributes com.apple.FinderInfo & com.apple.ResourceFork for icon file (name: Icon\r) Hide the icon file (name: Icon\r) We can use stat and xattr modules to do this. – TougherApollo1 Aug 29 '16 at 06:53
  • Will add the code in my git for further reference – TougherApollo1 Aug 29 '16 at 06:53
  • I'd love to see your code to do this. Can you link to your git where you put it? Thanks @TougherApollo1 – Dave Oct 14 '20 at 22:52

1 Answers1

2

Let we have a icon.icns file:

  1. Read the com.apple.ResourceFork extended attribute from the icon file
  2. Set the com.apple.FinderInfo extended attribute with folder icon flag
  3. Create a Icon file (name: Icon\r) inside the target folder
  4. Set extended attributes com.apple.FinderInfo & com.apple.ResourceFork for icon file (name: Icon\r)
  5. Hide the icon file (name: Icon\r)

We can use stat and xattr modules to do this.