Re: [MacPerl-Toolbox] Mac::OSA::Simple and Applescript properties

[email protected] (Chris Nandor) Thu, 18 Jul 2002 18:48:07 -0400
Newsgroups perl.macperl.toolbox
Message-ID <p05111b14b95cf48ba7ba@[10.0.1.177]>
At 23:48 +0200 2002.07.18, Bart Lateur wrote:
>I'd think this isn't quite the appropriate behaviour... Is something
>wrong related to some contextid (a phrase I picked up from the Mac::OSA
>docs )?
>
>	#! perl -wl
>	use Mac::OSA::Simple;
>	my $script = compile_applescript(<<'SCRIPT') or die $^E;
>	property foo: 20
>	set foo to foo + 1
>	SCRIPT
>	print $script->execute;
>	print $script->execute;
>	print $script->execute;
>
>This prints:
>
>	21
>	21
>	21
>
>I would have expected
>
>	21
>	22
>	23
>
>i.e. the context for the property should be retained between
>invocations.
>
>No?

Well, I changed line 178 from:
    $self->{ID} = OSACompile($self->{COMP}, $self->{SCRIPT}, 0) or

to:
    $self->{ID} = OSACompile($self->{COMP}, $self->{SCRIPT},
kOSAModeCompileIntoContext) or

And it gets the behavior you expect.  I am not entirely sure this is the
Right Thing, although it certainly seems to be; if it is the right thing, I
wonder if it should be an option.

Thoughts?

Note that Mac::OSA::Simple is by far the least-used module, judging from
user feedback, that I've released, so it's surely got some room for
improvement.  :-)

If I had the time, I would read up on the relevant chapters of Inside
Macintosh: Interapplication Communication, but at present, I do not have
the time, so feedback is more than welcome.

FWIW, I did this after the above change:

	#!perl -wl
	use Mac::OSA::Simple;
	my $file = "Bourque:Desktop Folder:osatest";
	my $script;

	if (-e $file) {
		$script = load_osa_script($file, 1);
	} else {
		$script = compile_applescript(<<'SCRIPT') or die $^E;
		property foo: 20
		set foo to foo + 1
	SCRIPT
	}

	print $script->execute;
	print $script->execute;
	print $script->execute;
	$script->save($file); # save with context

Each time it runs, it executes three times and saves the context at the
end, so when it is run three times:

	21
	22
	23
	24
	25
	26
	27
	28
	29

-- 
Chris Nandor                      [email protected]    http://pudge.net/
Open Source Development Network    [email protected]     http://osdn.com/