diff options
author | Mike Clarke <mike@lambdafunctions.com> | 2018-11-29 17:17:30 +0000 |
---|---|---|
committer | Mike Clarke <mike@lambdafunctions.com> | 2018-11-29 17:17:30 +0000 |
commit | 46760080c149ce7e61225330765c418b26174098 (patch) | |
tree | dd283401706e7292542b3c5617e3018e939e2b21 /ports/darwin_dmg/package_darwin_dmg.pl | |
parent | 68ae5111bbf372a32d1bf62f1ed18d34e0880078 (diff) |
Add Swift helper to set custom file icons
Diffstat (limited to 'ports/darwin_dmg/package_darwin_dmg.pl')
-rwxr-xr-x | ports/darwin_dmg/package_darwin_dmg.pl | 35 |
1 files changed, 2 insertions, 33 deletions
diff --git a/ports/darwin_dmg/package_darwin_dmg.pl b/ports/darwin_dmg/package_darwin_dmg.pl index 00ea95b..7c3ade6 100755 --- a/ports/darwin_dmg/package_darwin_dmg.pl +++ b/ports/darwin_dmg/package_darwin_dmg.pl @@ -63,33 +63,6 @@ die $USAGE if @ARGV != 2 or $mm !~ m{ \A \d{2} \z }msx or $mm < 1 or $mm > 12; -# Sadly, Apple decided to remove the `-i` / `--addicon` option from the `sips` -# utility. Therefore, use of Cocoa is required, which we do via Python, -# which has the added advantage of creating a _set_ of icons from the source -# image, scaling as necessary to create a 512 x 512 top resolution icon -# (whereas sips -i created a single, 128 x 128 icon). -# -# Thanks go to https://github.com/mklement0/fileicon/blob/master/bin/fileicon -# and https://apple.stackexchange.com/a/161984/28668 -# -# Note: setIcon_forFile_options_() seemingly always indicates True, even with -# invalid image files, so we attempt no error handling in the Python code. -sub set_icon { - croak if not @_; - my ($img_file, $target_file) = @_; - - print "Setting icon for $target_file\n" if $opt_verbose; - - my $rc = system(qq{/usr/bin/python - "$img_file" "$target_file" <<'EOF' -import Cocoa -import sys - -Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc().initWithContentsOfFile_(sys.argv[1].decode('utf-8')), sys.argv[2].decode('utf-8'), 0) -EOF - }); - die if $rc != 0; -} - sub run { croak if not @_; my (@command) = @_; @@ -159,16 +132,12 @@ run "CpMac -r '$src_dir' '$vol_dir'"; run "cp ../HOW_TO_INSTALL.txt '$vol_dir/README.txt'"; run "cp -pr ../../../docs '$vol_dir/Docs'"; -run "touch '$vol_dir/Rakudo/Icon\r'"; run "cp ../2000px-Camelia.svg.icns $vol_dir/.VolumeIcon.icns"; -set_icon "../2000px-Camelia.svg.icns", "$vol_dir/Rakudo/bin/perl6"; +run "../fileicon set '$vol_dir/Rakudo/bin/perl6' ../2000px-Camelia.svg.icns"; run "mkdir $vol_dir/.background"; -run "cp ../installerbg.png $vol_dir/.background"; +run "cp ../installerbg.png $vol_dir/.background"; run "SetFile -c icnC '$vol_dir/.VolumeIcon.icns'"; run "SetFile -a C '$vol_dir'"; -run "SetFile -a C '$vol_dir/Rakudo'"; -run "SetFile -a C '$vol_dir/Rakudo/bin/perl6'"; -run "SetFile -a V '$vol_dir/Rakudo/Icon\r'"; print ">>> Adjusting sizes and positions in installation window\n"; |