Skip to content

Instantly share code, notes, and snippets.

@morgant
Created December 8, 2010 20:10
Show Gist options
  • Select an option

  • Save morgant/733828 to your computer and use it in GitHub Desktop.

Select an option

Save morgant/733828 to your computer and use it in GitHub Desktop.

Revisions

  1. morgant revised this gist Dec 11, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion clipcat
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    #
    # clipcat - Concatenate and print Text Clippings.
    #
    # v0.1 2010-11-18 - David Kendall <https://gist.github.com/705623>
    # v0.1 2010-11-18 - David Kendal <https://gist.github.com/705623>
    # Initial version. Used with permission.
    # v0.2 2010-12-08 - Morgan Aldridge <[email protected]>
    # Now concatenates multiple text clippings. Usage instructions.
  2. morgant revised this gist Dec 8, 2010. 1 changed file with 50 additions and 35 deletions.
    85 changes: 50 additions & 35 deletions clipcat
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,13 @@
    #!/usr/bin/perl -w

    # clipcat: the misleadingly-named textClipping outputter for Mac OS X.
    # you'll need MacPerl and DeRez. I think the latter ships with OS X,
    # but at least comes with the dev tools (which by definition you have
    # if you installed MacPerl)
    # -------------------------
    # by David Kendal (http://dpk.org.uk / @dpkendal)
    # bug reports & comments to the address on http://dpk.org.uk/contact/
    #
    # clipcat - Concatenate and print Text Clippings.
    #
    # v0.1 2010-11-18 - David Kendall <https://gist.github.com/705623>
    # Initial version. Used with permission.
    # v0.2 2010-12-08 - Morgan Aldridge <[email protected]>
    # Now concatenates multiple text clippings. Usage instructions.
    #

    use strict;
    use utf8;
    @@ -15,41 +16,55 @@ use File::Basename;

    my $script = basename($0);

    my $file = $ARGV[0];
    my $fileinfo = MacPerl::GetFileInfo($file);

    $file = escape($file);

    if (!-e $file) {
    print STDERR "$script: no such file $file.\n"; exit 1;
    } elsif ($fileinfo ne 'clpt') {
    print STDERR "$script: file $file is not a clipping.\n"; exit 1;
    }

    my @resdata = `DeRez -only 'utf8' '$file'`;
    shift(@resdata);
    pop(@resdata); pop(@resdata);

    foreach (@resdata) {
    my $line = $_;
    chomp $line;
    $line =~ s{^\t\$"|" +/\*.+\*/$}{}g;
    my @blobs = split / /, $line;
    foreach (@blobs) {
    my $blob = $_;

    my $hex1 = substr $blob, 0, 2;
    my $hex2 = substr $blob, 2, 3;
    if ($ARGV[0]) {
    while ($ARGV[0]) {
    my $file = $ARGV[0];
    my $fileinfo = MacPerl::GetFileInfo($file);

    print chr(hex($hex1)).chr(hex($hex2));
    $file = escape($file);

    if (!-e $file) {
    print STDERR "$script: no such file $file.\n"; exit 1;
    } elsif ($fileinfo ne 'clpt') {
    print STDERR "$script: file $file is not a clipping.\n"; exit 1;
    }

    my @resdata = `DeRez -only 'utf8' '$file'`;
    shift(@resdata);
    pop(@resdata); pop(@resdata);

    foreach (@resdata) {
    my $line = $_;
    chomp $line;
    $line =~ s{^\t\$"|" +/\*.+\*/$}{}g;
    my @blobs = split / /, $line;
    foreach (@blobs) {
    my $blob = $_;

    my $hex1 = substr $blob, 0, 2;
    my $hex2 = substr $blob, 2, 3;

    print chr(hex($hex1)).chr(hex($hex2));
    }
    }

    shift(@ARGV);
    }
    exit 0;
    } else {
    print STDERR "$script: No files were specified.\n\n";
    usage();
    exit 1;
    }

    exit 0;
    sub usage {
    print "Usage: clipcat [options] file ...\n";
    print " -h print these usage instructions\n";
    }

    sub escape { # http://cl.ly/3JGN -- should work to escape the filename
    my $text = shift; # for handing to DeRez
    $text =~ s/\\/\\\\/g;
    $text =~ s/'/\\'/g;
    return $text;
    }
    }
  3. @dpk dpk created this gist Nov 18, 2010.
    55 changes: 55 additions & 0 deletions clipcat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    #!/usr/bin/perl -w

    # clipcat: the misleadingly-named textClipping outputter for Mac OS X.
    # you'll need MacPerl and DeRez. I think the latter ships with OS X,
    # but at least comes with the dev tools (which by definition you have
    # if you installed MacPerl)
    # -------------------------
    # by David Kendal (http://dpk.org.uk / @dpkendal)
    # bug reports & comments to the address on http://dpk.org.uk/contact/

    use strict;
    use utf8;
    use MacPerl;
    use File::Basename;

    my $script = basename($0);

    my $file = $ARGV[0];
    my $fileinfo = MacPerl::GetFileInfo($file);

    $file = escape($file);

    if (!-e $file) {
    print STDERR "$script: no such file $file.\n"; exit 1;
    } elsif ($fileinfo ne 'clpt') {
    print STDERR "$script: file $file is not a clipping.\n"; exit 1;
    }

    my @resdata = `DeRez -only 'utf8' '$file'`;
    shift(@resdata);
    pop(@resdata); pop(@resdata);

    foreach (@resdata) {
    my $line = $_;
    chomp $line;
    $line =~ s{^\t\$"|" +/\*.+\*/$}{}g;
    my @blobs = split / /, $line;
    foreach (@blobs) {
    my $blob = $_;

    my $hex1 = substr $blob, 0, 2;
    my $hex2 = substr $blob, 2, 3;

    print chr(hex($hex1)).chr(hex($hex2));
    }
    }

    exit 0;

    sub escape { # http://cl.ly/3JGN -- should work to escape the filename
    my $text = shift; # for handing to DeRez
    $text =~ s/\\/\\\\/g;
    $text =~ s/'/\\'/g;
    return $text;
    }