Skip to content

Instantly share code, notes, and snippets.

@rderewianko
Created September 20, 2017 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rderewianko/d842d07bd007f45f00de855f781f66a6 to your computer and use it in GitHub Desktop.
Save rderewianko/d842d07bd007f45f00de855f781f66a6 to your computer and use it in GitHub Desktop.
Give a folder an icon on a mac
#!/usr/bin/env python
import Cocoa
import sys
Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc().initWithContentsOfFile_(sys.argv[1].decode('utf-8')), sys.argv[2].decode('utf-8'), 0) or sys.exit("Unable to set file icon")
@LeeBinder
Copy link

Hi @rderewianko I'm running macOS Monterey and have current python v.3.11 as well as legacy v.2.7.18 installed. Regardless if I invoke python2 or python3, I get:

import Cocoa ImportError: No module named Cocoa

Trying several hints on the web how to re-add Cocoa didn't help.

Do you have any idea how to make your script work again with current macOS? That would be awesome 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment