The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

#!/usr/local/bin/perl
use strict;
my $file = shift @ARGV || 'clipboard';
my $pb = Mac::Pasteboard->new ();
my @img = $pb->paste_all ('public.image')
or die "No data conforming to 'public.image' found.\n";
foreach my $item (@img) {
my $tags = $pb->flavor_tags ($item->{flavor});
my $fn = $tags->{extension} ? "$file.$tags->{extension}" : $file;
warn "Creating $fn\n";
open (my $fh, '>', $fn) or die "Failed to open $fn: $!\n";
binmode $fh;
print $fh $item->{data};
close $fh;
}