These days there are easier ways to do both of these things under OS X. The two examples are provided as a reference for how to use DropScript.

Example 1

This one makes a bunch of files into a tarball

#!/usr/bin/perl 

#/sw/bin/tar czf "/Users/novak/Desktop/New Archive.tar.gz" "$@" 

if (@ARGV == 0) {
    # this should never happen since the script should always get 
    # arguments via drag+drop
    die;
}
elsif (@ARGV == 1) {
    # Only one argument probably means the user dragged 
    # a folder.  Also possibly a single file.  
    # Strip everything except the filename
    @sheep = split("/", $ARGV[0]);
    pop @sheep;
    $pattern = join("/", @sheep);    
}
else {
    # if there's more than one argument, the user is trying
    # to make an archive of a bunch of files...  Strip common 
    # parts of the path before making the archive b/c the script 
    # always gets the full pathname.
    $sheep = $ARGV[0];
    @sheep = split("/", $sheep);
    $n = @sheep;
    
    for ($i=1; $i<=$n; $i++) {
        $success = 1;
        $pattern = join("/", @sheep);
        foreach(@ARGV) {
            if (!/^$pattern/) {
                $success=0;
            }
        }
        if ($success==1) {
            last;
        }
        else {
            pop(@sheep);
        }
    }
}
foreach (@ARGV) {
    s+$pattern/++;
    push @args, $_;
}

$args = join("\" \"", @args);
$args = "\"$args\"";
print "/sw/bin/tar czf /Users/novak/Desktop/Archive.tgz --directory \"$pattern\" $args";

Example 2

This one converts a Postscript file to a PDF file and launches Acrobat to view it.

#!/usr/bin/perl -w

use Env qw(PATH);

#Connect tcsh to a pipe into which it'll spit the path
open ENVFILE, "tcsh -c \'source ~/.cshrc; echo \$PATH\' |";
#Grab the path
$cshpath = <ENVFILE>;
close ENVFILE;
# Add it to the path in the current environment
$PATH = "$cshpath:".$PATH;

foreach $in (@ARGV) {
    $out = $in;
    $out =~ s/ps$/pdf/;
    system "ps2pdf $in $out";
    system "open $out";
}

Answers/Code/DropscriptExamples (last edited 2007-09-13 00:03:30 by GregNovak)