#!/usr/bin/perl # PDF Retrieval Demonstration Script # Author: Scott Garner # Last Updated: 2005-10-20 use strict; use MacPerl 'DoAppleScript'; # Find the POSIX path to the desktop; my $desktopPath = MacPerl::DoAppleScript qq{ return posix path of (path to desktop folder) as text }; $desktopPath =~ s/^"|"$//g; print "Enter the package ID for the company in question:\n"; my $packageID = ; chomp $packageID; my $companyURL = "http://134.186.208.228/caleasi/search.asp?TASKNAME=xshowDocs&PackageID=$packageID"; my $packageSource = `curl -s "$companyURL"` # Search for the individual documents in the # package page's source and process each one. my @docURLs = ($packageSource =~ m{()}ig); my $curDocURL; foreach $curDocURL (@docURLs) { my $docID; my $docName; # Extract both the document ID and name from the URL. ($docID, $docName) = ($curDocURL =~ m{^.*DocID=(\d+).*>(.+)<.*$}i); # Load the container page--the final PDF document # doesn't exist in the expected location until # this page has been accessed. my $containerURL = "http://134.186.208.228/caleasi/search.asp". "?TASKNAME=xShowPDF&DocID=$docID"; my $containerSource = `curl -s "$containerURL"`; # Retrieve the final PDF using the commandline # utility 'curl'. my $pdfURL = "http://134.186.208.228/caleasi/PDFDocs/$docID.PDF"; my $pdfPath = qq{"$desktopPath$packageID/$docID-$docName.pdf"}; `curl --silent --create-dirs --output $pdfPath $pdfURL`; } # Tell Finder to beep so the user knows the script # has finished. MacPerl::DoAppleScript qq{ tell application "Finder" to beep 2};