2 # Copyright © 2015 Dave Odell <dmo2118@gmail.com>
4 # Permission to use, copy, modify, distribute, and sell this software and its
5 # documentation for any purpose is hereby granted without fee, provided that
6 # the above copyright notice appear in all copies and that both that
7 # copyright notice and this permission notice appear in supporting
8 # documentation. No representations are made about the suitability of this
9 # software for any purpose. It is provided "as is" without express or
12 # This is a replacement for seticon from http://osxutils.sourceforge.net/.
20 my $progname = $0; $progname =~ s@.*/@@g;
21 my ($version) = ('$Revision: 1.4 $' =~ m/\s(\d[.\d]+)\s/s);
26 my ($icon, $target) = @_;
27 my $target_res = $target;
30 $target_res = $target_res . "/Icon\r";
33 # Rez hates absolute paths, apparently.
34 if ($icon =~ m@^/@s) {
37 $icon =~ s@^\Q$cwd/@@s;
40 # The Rez language is documented in "Building and Managing Programs in MPW,
41 # Second Edition". No longer available on Apple's servers, it can now be
43 # http://www.powerpc.hu/manila/static/home/Apple/developer/Tool_Chest/Core_Mac_OS_Tools/MPW_etc./Documentation/MPW_Reference/Building_Progs_In_MPW.sit.hqx
45 my $pgm = "Read 'icns' (kCustomIconResource) \"$icon\";\n";
47 # Rez can read from stdin, but only if it is a file handle, not if it
48 # is a pipe (OS X 10.9, Xcode 5; OSX 10.11, Xcode 6).
50 my ($rez_fh, $rez_filename) = File::Temp::tempfile(DIR => '.', UNLINK => 1);
59 print STDERR "$progname: exec: " . join(' ', @cmd) . "\n$pgm\n"
63 # my $pid = open2 ($out, $in, @cmd);
71 exit ($exit) if $exit;
73 # Have to also inform Finder that the icon is there, with the
74 # com.apple.FinderInfo xattr (a FolderInfo struct).
75 @cmd = ('SetFile', '-a', 'C', $target);
78 exit ($exit) if $exit;
82 print "Usage: $progname -d source [file...]\n";
90 if (m/^--?verbose$/s) { $verbose++; }
91 elsif (m/^-v+$/s) { $verbose += length($_)-1; }
92 elsif (m/^-d$/s) { $d = 1; }
93 elsif (!defined($src)) { $src = $_; }
94 elsif (!defined($dst)) { $dst = $_; }
97 usage() unless ($d && $src);
98 set_icon ($src, $dst);