Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 04-09-2007, 03:07 PM   #1
mankoff
Triple-A Player
 
Join Date: Mar 2004
Location: NYC
Posts: 60
Set File Icon on Command Line

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?
__________________
http://spacebit.dyndns.org
mankoff is offline   Reply With Quote
Old 04-11-2007, 03:04 PM   #2
ActiveMan
Guest
 
Posts: n/a
Post Custom icons

In both cases the approach is similar:

To set a file custom icon activate the C file attribute:

$ SetFile -a C mydoc.txt

And the icon must be write into the resource fork.

To set a folder custom icon activate the folder custom icon:

$ SetFile -a C myfolder

and create a Icon? file within the folder with the icon stored in the resource fork:

$ cat Icon?/..namedfork/rsrc
  Reply With Quote
Old 04-11-2007, 04:04 PM   #3
mankoff
Triple-A Player
 
Join Date: Mar 2004
Location: NYC
Posts: 60
Quote:
Originally Posted by ActiveMan
To set a file custom icon activate the C file attribute:

$ SetFile -a C mydoc.txt

And the icon must be write into the resource fork.

But with this syntax, where do I specify the image? How do I write it into the resource fork? Just "cp icon.tiff mydoc.txt/rsrc/" ?
__________________
http://spacebit.dyndns.org
mankoff is offline   Reply With Quote
Old 04-12-2007, 03:10 PM   #4
ActiveMan
Guest
 
Posts: n/a
Hello. Try using ResKnife utility to edit the resource fork of the Icon? file. Before editing the Icon? file you can copy the icon? file to another file:

$ ditto Icon? myicon
$ SetFile -a v myicon
  Reply With Quote
Old 04-13-2007, 08:12 AM   #5
mankoff
Triple-A Player
 
Join Date: Mar 2004
Location: NYC
Posts: 60
The Icon? file is for folders, not documents.
__________________
http://spacebit.dyndns.org
mankoff is offline   Reply With Quote
Old 04-14-2007, 04:45 AM   #6
ActiveMan
Guest
 
Posts: n/a
Red face

Yes, files can have a custom icon in the resource fork with an entry of type icns. If a file has not a custom icon, finder shows the default icon according to its extension, creator code, or type code.
  Reply With Quote
Old 04-14-2007, 07:36 AM   #7
biovizier
All Star
 
Join Date: May 2004
Location: london on ca
Posts: 930
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'
biovizier is offline   Reply With Quote
Old 04-15-2007, 10:21 AM   #8
ActiveMan
Guest
 
Posts: n/a
Right answer. BTW, do you know a command line to list the resources of a file.
  Reply With Quote
Old 04-18-2007, 11:36 AM   #9
mankoff
Triple-A Player
 
Join Date: Mar 2004
Location: NYC
Posts: 60
Perfect! That is exactly what I was looking for, and very clearly explained.

Thank you,

-k.
__________________
http://spacebit.dyndns.org
mankoff is offline   Reply With Quote
Old 04-19-2007, 10:38 AM   #10
mankoff
Triple-A Player
 
Join Date: Mar 2004
Location: NYC
Posts: 60
RezDet in the /Developer/Tools folder should do this. Looks like RezWack might too.
__________________
http://spacebit.dyndns.org
mankoff is offline   Reply With Quote
Old 04-22-2007, 09:34 AM   #11
ActiveMan
Guest
 
Posts: n/a
Hello, thank you, but apparently RezDet is not longer avaiable on OS X:

Code:
$ RezDet .
".":
File "."; ### RezDet - Encountered error -43. (GetSysErrText not available in BSD environment. Sorry.) - Fatal I/O error.
  Reply With Quote
Old 04-22-2007, 12:23 PM   #12
mankoff
Triple-A Player
 
Join Date: Mar 2004
Location: NYC
Posts: 60
Works on files for me, not folders.
__________________
http://spacebit.dyndns.org
mankoff is offline   Reply With Quote
Old 04-22-2007, 05:04 PM   #13
2pac
Prospect
 
Join Date: Mar 2007
Posts: 31
it works both (on files and folders) to me. really good manual for newbies. Thanks
2pac is offline   Reply With Quote
Old 08-10-2009, 08:08 AM   #14
Lutin
Major Leaguer
 
Join Date: May 2006
Location: Paris, France
Posts: 311
The instruction on post #7 works for me.

Once I have added an icon to my file, I need to host it on a ftp server.
In the transfer, rsrc fork are not preserved, and when it's finally downloaded, the icon is not visible.

So, I tried to flatten the file first, with RezWack
Code:
/Developer/Tools/RezWack -d myFile -r myFile -o myNewFlatFile
As soon as I do this, the custom icon is not visible anymore.

Any hint on how to do this? (Give a file a custom icon, and have it preserved when being transferred over ftp. The server is an XServe, if it has any incidence).
Lutin is offline   Reply With Quote
Old 08-10-2009, 10:04 AM   #15
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,938
Quote:
Originally Posted by Lutin
So, I tried to flatten the file first, with RezWack
Code:
/Developer/Tools/RezWack -d myFile -r myFile -o myNewFlatFile
As soon as I do this, the custom icon is not visible anymore.

Did you run some command to undo the effect of the RezWack? You need to.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 08-10-2009, 10:40 AM   #16
Lutin
Major Leaguer
 
Join Date: May 2006
Location: Paris, France
Posts: 311
Quote:
Originally Posted by hayne
Did you run some command to undo the effect of the RezWack? You need to.

Hayne, I am not sure what you mean.
Could you elaborate?
I was under the impression RezWack would combine a data fork and rsrc fork into one file, allowing to not loose any part when being manipulated by a program that doesn't respect forks.
Lutin is offline   Reply With Quote
Old 08-10-2009, 01:29 PM   #17
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,938
Quote:
Originally Posted by Lutin
I was under the impression RezWack would combine a data fork and rsrc fork into one file, allowing to not loose any part when being manipulated by a program that doesn't respect forks.

Yes - but when you actually want the file to be used (for an icon), you need the resource fork back the way it was before.
I.e. RezWack produces something like an archive format - not something that can be used by software that expects there to be an actual resource fork.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 08-10-2009, 04:48 PM   #18
Lutin
Major Leaguer
 
Join Date: May 2006
Location: Paris, France
Posts: 311
Ok, I see. Thank you for the clarification. Now I understand that it's not what I need.

Is there any way to set a custom icon to a file, upload this file to a webserver and still have the custom icon attached to the file and visible by users when they have downloaded the file?

In my case, I need to set up a dmg to have a custom icon. If needed, the server can be an XServe.
Lutin is offline   Reply With Quote
Old 08-10-2009, 06:11 PM   #19
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,938
Quote:
Originally Posted by Lutin
In my case, I need to set up a dmg to have a custom icon.

There are various 3rd-party utilities aimed at developers that handle DMG attributes like this.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 08-11-2009, 01:37 AM   #20
Lutin
Major Leaguer
 
Join Date: May 2006
Location: Paris, France
Posts: 311
Hayne, once again thank you for your reply.
You are of great value to this forum.

I do not want to customize the inside of the DMG (like the icon of the Volume mount once open, or the background), but really the icon of the DMG file (what you see in the finder when you have just downloaded it).

I want to customize the icon of this file like you would do by showing the Get Info panel for the DMG file, and then drag and drop an image onto the icon.
This part is working, but does not "stick" when you transfer the file onto a ftp server.

If the tools you are thinking about allow this, could you point me to one? The only ones I could find only do what I described in the first part of this message.
Lutin is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 03:35 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, 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.