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

[MacPerl] Using the Resource Mangler from MacPerl



I ran into the following while working on the aete converter thing. I don't
know if it's documented in the MacPerl documentation anywhere. Even if it
is, it's probably worth repeating. 

When you read a resource on the Mac, the first file searched is the current
resource file. If the resource isn't found there, then the application file
is searched, and then possibly the sytem file. This is the way the Mac has
worked from day one and normally isn't a big deal since the application
developer knows what resources are in the application.

When you use the resource module under MacPerl (or MPW perl), the current
application is either MacPerl (or MPW). Therefore if you attemp to access a
resource, and it isn't where you thought it was, then the resource will be
read from MacPerl (or MPW) if a resource of the proper type and ID exists
there. That's how I ended up with the processed version of MacPerl's aete
resource in my previous message. The target application wasn't scriptable
and so it didn't have an aete resource. As a result, MacPerl's aete got
processed. This also happened once when I was running under MPW. The
solution is to do something like what I have below, where I use the
HomeResFile call to check the reference number of the file containing the
resource against the the reference number of the file I opened.

You should also explicitly close any opened resource files, since they will
otherwise remain open after your script has quit. If you don't close the
resource file, any resources that haven't been released will stick around
in MacPerl's application heap.

---------------
use Mac::Memory;
use Mac::Resources;

$handleIndex = 0;
$target = $ARGV[0];
$RF = OpenResFile($target);
if ( !defined($RF) || $RF == 0) {
	die ("No Resource Fork available");
}

$aeteHandle = GetResource("aete", 0);
if (!defined($aeteHandle) || $aeteHandle == 0 || HomeResFile($aeteHandle)
!= $RF) {
	die ("Application is not scriptable");
}
---------------
				 	
later,

---Dave---

=========================================================
David C. Schooley                 | Hey, New York,
Ph.D. in progress                 |  Please restore Georgia's state flag
Georgia Tech Electric Power       | to its rightful place in your
email: schooley@ece.gatech.edu    | capitol building.
http://www.ee.gatech.edu/users/schooley/
---------------------------------------------------------
Cyberdog ---A Product of Apple Computer, Inc.
---------------------------------------------------------