TougherApollo1
TougherApollo1

Reputation: 107

How to change icon of a MAC OS folder using Python Script and Terminal commands?

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.

Upvotes: 3

Views: 1840

Answers (1)

TougherApollo1
TougherApollo1

Reputation: 107

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.

Upvotes: 2

Related Questions