[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Outputting to a printer (corrected)



>I get the file name & path printed instead of the file contents, with text
>clippings and dragged and dropped files. Clipboard contents are printed
>correctly. Arghhh!


Ooops! Sorry about that. I really must do a better job of double checking
my code before I send it. Sounds like a good New Year's resolution.

You're right, Larry. When a file is dropped on a droplet $ARGV[0] will
contain the path name. The following code uses this path to open this code.

Be sure to drag any clippings to the desktop first, then drop it on the
droplet.

Be aware that this code first prints to a MacPerl window and then has
MacPerl print the results. This MacPerl window is limited in size so some
files might not print completely. I used MacPerl because I knew everyone on
the MacPerl list would have it.

Another way would be to have your script save the file to disk first and
then have AppleScript load it with your word proccessor and print the file
with that.

I actually didn't save the code as a droplet. I saved the code as a regular
text file with the name "print_perl_clipping.pl". Then I created a script
with this single line of code...
    do "print_perl_clipping.pl";

I save this one line script as a MacPerl droplet. Sometimes I even create
an alias to the droplet and put this alias on the desktop so I can drop
clippings and files on it for my original code to process.

David Seay
http://www.mastercall.com/g-s


-------------------------------------------------------------------------------
-------------------------------------------------------------------------------

#!perl

use Mac::Resources;
use Mac::Memory;
package Dartmouth;

&MacPerl::LoadExternals("clipboard.XFCN"); # XCMD for clipboard processing
package main;

if (MacPerl::GetFileInfo($ARGV[0]) eq 'clpt') {
	$fileref = FSpOpenResFile(@ARGV, 1);
	if (defined($fileref)) {
		$reshand = Get1Resource('TEXT', 256);
		if ($reshand) { $clip = $reshand->get() }  # get text clipping
	}
	CloseResFile $fileref;
} elsif ($ARGV[0]) {
	$file = $ARGV[0];      # get a dropped, previously saved file
	open(FILEDATA, "$file" || die "Can't open $file... $^E" );
	@fileLines = <FILEDATA>;
	close(FILEDATA);
	$clip = join("",@fileLines);
} else { $clip = &Dartmouth::Clipboard() }   # get clipboard contents


if ($clip) {
	print "$clip\n";
	exit(0);
	&MacPerl::DoAppleScript(<<"END_SCRIPT");
	tell application "MacPerl"
		print document 1
		Close Window "MacPerl"
	end tell
END_SCRIPT
} else {
	print "\a";
	&MacPerl::Quit(0); # change to '&MacPerl::Quit(2);' to quit MacPerl
after ending the script
}



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch