![]() |
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? |
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 |
Quote:
|
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 |
The Icon? file is for folders, not documents.
|
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.
|
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.jpgCode:
/Developer/Tools/DeRez -only icns donorfile.jpg > tempicns.rsrcCode:
/Developer/Tools/Rez -append tempicns.rsrc -o recipientfile.xyzCode:
/usr/bin/osascript -e 'tell application "Finder" to quit' -e 'delay 2' -e 'tell application "Finder" to activate' |
Right answer. BTW, do you know a command line to list the resources of a file.
|
Perfect! That is exactly what I was looking for, and very clearly explained.
Thank you, -k. |
RezDet in the /Developer/Tools folder should do this. Looks like RezWack might too.
|
Hello, thank you, but apparently RezDet is not longer avaiable on OS X:
Code:
$ RezDet . |
Works on files for me, not folders.
|
it works both (on files and folders) to me. really good manual for newbies. Thanks
|
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 myNewFlatFileAny 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). |
Quote:
|
Quote:
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. |
Quote:
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. |
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. |
Quote:
|
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. |
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.
|
Sorry for hijacking your thread. But it refers to what you said in the beginning:
Quote:
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 |
Quote:
Code:
#! /usr/bin/env pythonCode:
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.