Skip to main content
Added decoding of utf-8 to unicode (otherwise it doesn't work for non-ascii filenames) and handling of success/fail
Source Link
kolen
  • 121
  • 1
  • 6

In addition to Ruby, here's a Python version:

#!/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") 

./set-image.py image.png myfile

Python that pre-installed in Mac OS already has PyObjC so you don't have to install any packages.

In addition to Ruby, here's a Python version:

#!/usr/bin/env python import Cocoa import sys  Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc ().initWithContentsOfFile_(sys.argv[1]), sys.argv[2], 0) 

./set-image.py image.png myfile

Python that pre-installed in Mac OS already has PyObjC so you don't have to install any packages.

In addition to Ruby, here's a Python version:

#!/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") 

./set-image.py image.png myfile

Python that pre-installed in Mac OS already has PyObjC so you don't have to install any packages.

spelling
Source Link
Jawa
  • 2.5k
  • 7
  • 20
  • 25

In addition to rubyRuby, pythonhere's a Python version:

#!/usr/bin/env python import Cocoa import sys Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc ().initWithContentsOfFile_(sys.argv[1]), sys.argv[2], 0) 

./set-image.py image.png myfile

Python that pre-installed in Mac OS already has PyObjC so you don't have to install any packages.

In addition to ruby, python version:

#!/usr/bin/env python import Cocoa import sys Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc ().initWithContentsOfFile_(sys.argv[1]), sys.argv[2], 0) 

./set-image.py image.png myfile

Python that pre-installed in Mac OS already has PyObjC so you don't have to install any packages.

In addition to Ruby, here's a Python version:

#!/usr/bin/env python import Cocoa import sys Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc ().initWithContentsOfFile_(sys.argv[1]), sys.argv[2], 0) 

./set-image.py image.png myfile

Python that pre-installed in Mac OS already has PyObjC so you don't have to install any packages.

Source Link
kolen
  • 121
  • 1
  • 6

In addition to ruby, python version:

#!/usr/bin/env python import Cocoa import sys Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc ().initWithContentsOfFile_(sys.argv[1]), sys.argv[2], 0) 

./set-image.py image.png myfile

Python that pre-installed in Mac OS already has PyObjC so you don't have to install any packages.

Post Made Community Wiki by kolen