Mac GeekeryGet your geek on. |
|
blog advertising is good for you
recent popular content
User login
|
Alex Lovett asks: QuestionI’m trying to automate Mac icon creation for folders and files headlessly via the commandline or AppleScript. I’m dynamically creating alpha masked PNG’s and wish to transfer those to Folder/File icons with no user intervention, all in the background. Also for the sake of when Leopard comes out, it would be great to have 512×512 icon support. Though ANY support would be welcomed. While I’d like to be using some Apple standard system for correctly applying icons, Folder icons are open to some hackery as they store the icon inside the folder itself as an ‘Icon’ file in the format of .icns, however I know of no way to automatically generate an icns file, and even if I could, you cant just rename your file to ‘Icon’ as the name is in fact ‘Icon^M’ or rather ‘Icon’ folowed by a carriage return, which is impossible to do as far as I know. Any help in this endevour would be greatly appreciated. AnswerThere exists no tool to do this. So I wrote one. The following is released under the one, true open source license: MIT.
What does all that do? It reads any graphic format that Preview can read (yes, even PDF) and then sets the icon of the file to that graphic, doing the proper conversions for you. Ain’t Cocoa grand? You would compile the above into a universal tool like so: $ gcc -arch i386 -arch ppc -framework AppKit -o SetIcon SetIcon.m You’ll likely need someone logged in for this to work, as NSWorkspace generally requires that. The source and universal binary are below.
About Adam Knight
Author Biography Adam Knight is one of the founders of Mac Geekery and is a geek at heart. Programmer by day, hacker by night, his daily life revolves around the Macintosh platform, which he has been a user and programmer for since the early days of System 7 when his LCII replaced his Apple //c. In-between tech jobs, he’s managed to learn the basics of any web hacker: PHP, MySQL, Perl, Apache, Linux, *BSD, and the intricacies of ./configure —prefix=~/bombshelter/. Today, codepoet is concentrating on blogging again, writing some software for the Mac by himself (including Notae) and for his company (such as Switchblade) and has a few other toys coming out soon. Bug him over AIM or email [link fixed]. |
It would be brilliant if the tool had an option to save the icon file…
Something like
Thanks for the tool. I love you!
There is also a set of command-line utilities called osxutils:
http://osxutils.sourceforge.net/
The command “seticon” in the osxutils bundle will copy the icon (rather than the graphic) from one file to another. It’s slightly different than what’s called for in the question, but very handy nonetheless. In case anyone’s interested.
-systemsboy
I have to make compliment to this useful tool.
Work better than finder for trasparency.
I stumbled across this blog and thought it interesting. ( I have a semi off topic question though )
I have been trying to figure out how to create “alias” via the commandline for mac.
By alias I mean the ones in the GUI (synonymous with m1cr0scoffs “shortcuts”) not the term used to alias terms in a shell script.
GUI aliases have a distinct advantage over the links you can create via the CLI using ln,
being that you can move the file of an alias to a different directory and still have it work, and it can point to files across devices ( say my backup lacie drive folder ) this is where the ln command comes woefully short. I noticed that I can follow aliases via the command line just like any other link, but I cannot create them.
I guess that was a long rant to ask, if there is any way you know how to create Aliases via the commandline.