The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   OS X Developer (http://hintsforums.macworld.com/forumdisplay.php?f=27)
-   -   Set File Icon on Command Line (http://hintsforums.macworld.com/showthread.php?t=70769)

hayne 08-11-2009 10:28 AM

I don't know if any of the tools handle custom icons for the DMG itself, nor whether it is possible to have such a custom icon transfer automatically from a server. This might be possible if you used some file sharing protocol that supported resource forks.

Ann_at 08-17-2009 10:24 AM

Sorry for hijacking your thread. But it refers to what you said in the beginning:

Quote:

Originally Posted by mankoff (Post 371291)
Hi,

I know how to set custom folder icons via the command line, but have not been able to figure out how to do this for files. Does anyone know?

This interests me.
How do you set a custom folder icon via the command line?

one possibility should be to copy the Icon? file into the folder and then run

sudo /Developer/Tools/SetFile -a C FolderName

Is this really all? Any other way to do this?

kind regards, Ann

jimmytaker 12-15-2013 06:47 PM

Quote:

Originally Posted by biovizier (Post 372418)
You can use 'sips' to give an image file a custom icon of itself ('sips' acts on the original file so it might be safer to work on a copy):
Code:

/bin/cp imagefile.jpg donorfile.jpg
/usr/bin/sips -i donorfile.jpg

If you just wanted to give an image file a thumbnail custom icon of itself, you can stop there. Otherwise, if you have the "Developer" / "X Code" tools installed, you can use 'DeRez' and 'Rez' to manipulate the resources to copy the newly created 'icns' resource to a file:
Code:

/Developer/Tools/DeRez -only icns donorfile.jpg > tempicns.rsrc
Then copy the the temp file into the icns resource of the recipient file, and set the custom icon file attribute:
Code:

/Developer/Tools/Rez -append tempicns.rsrc -o recipientfile.xyz
/Developer/Tools/SetFile -a C recipientfile.xyz

Finally, restart the "Finder" to view the changes:
Code:

/usr/bin/osascript -e 'tell application "Finder" to quit' -e 'delay 2' -e 'tell application "Finder" to activate'

This is true, but it has one disadvantage - the icon is set with a low resolution only. So e.g. if you right click and choose quick look it will look pixelated even if the image you used had a high resolution. To battle this, I dug deeper and the following script sets a real .icns file and works for me:

Code:

#! /usr/bin/env python

from AppKit import *
import sys

NSWorkspace.sharedWorkspace().setIcon_forFile_options_(NSImage.alloc().initByReferencingFile_(sys.argv[2]), sys.argv[1], 0)

usage would be:

Code:

setIcon recipientfile.xyz icon.icns


All times are GMT -5. The time now is 05:51 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.