In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (John Delacour) 
wrote:

> I have exactly the same set-up.  The only difference seems to be my 
> pain threshold :-)

Yes, that whole extra second Mac::Glue takes over osascript can be annoying.  
I am only being half-facetious, I know it can be, depending on the context.  
But in most cases, it won't be significant.

You may not be aware, but unlike RunAppleScript(), the worst overhead 
involved with Mac::Glue is on script startup only, whereas with 
RunAppleScript() there will be slowness overhead associated with every call 
to the function.

[As a side note: again noting that the delay is entirely in the startup, I 
use Mac::Glue a lot in XChat scripts, and they are loaded in once and cached 
a la mod_perl, so there is no startup issue.  You get immediate results, 
just as one would expect from a compiled AppleScript.]


> The problem with your routine is that you need to display the dialog 
> in a process which a) has glue available and b) the user does not 
> want to activate.

I don't understand the complaint.  It's just like yours.  Yes, you need a 
glue, but that's a one-time operation ("% glue /Applications/Terminal"); 
it's not a big deal.  And yours targets the application too; what's the 
difference?


> Besides that, the user is required to learn a new way of expressing 
> the terminology rather than simply using the familiar AppleScript way.

You are assuming people on this list are familiar with AppleScript.  I make 
no such (false) assumption.  :)


> The routine using Mac::AppleScript seems so much simpler to me

Yes, of this I have no doubt.

> and it is possible to display dialogs without leaving the current 
> application, whether it be Terminal or the editor (at least the one 
> I'm using).

OK, I think you misunderstood.  It works just fine using any app as the 
target app, as long as it is scriptable, just like yours.


> done no precise timings.  Neither method is fast and 3 seconds to me 
> is an awful long time if you think what that might have taken on a 66 
> MHz machine.

Three seconds *including clicking Cancel*.  So it relies on silly user 
interaction, hence the note of the user/sys CPU times.  Here's a quick 
similarly "dumb" benchmark that relies on user interaction:


[EMAIL PROTECTED] pudge]$ time osascript -e 'tell app "Terminal" to choose file 
name with prompt "test1" default name "test2"'
real    0m1.136s
user    0m0.200s
sys     0m0.070s

[EMAIL PROTECTED] pudge]$ time perl -MMac::Glue -e 'my $glue = new Mac::Glue 
"Terminal"; $glue->choose_file_name(with_prompt => "test1", default_name => 
"test2");'
real    0m2.398s
user    0m1.120s
sys     0m0.210s

Woohoo, I clicked "Cancel" faster on that run.  :)  The real number is 0.27 
vs. 1.33 there.  About a second difference.


> use Mac::AppleScript qw(RunAppleScript);
> $asresult = RunAppleScript <<AS;
> tell app "Terminal"
>    display dialog "Enter a number:" default answer "55"
>    text returned of result as real
> end
> AS
> print $asresult**2 . $/;

use Mac::Glue;
my $glue = new Mac::Glue 'Terminal';
my $result = $glue->display_dialog('Enter a number:', default_answer => 55);
print $result->{text_returned}**2, "\n";

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

Reply via email to