At 12:48 +0900 2001.10.24, Nobumi Iyanaga wrote: >I would like to know how to write the AppleScript commands "activate" and >"open document" in AppleEvent, within a MacPerl script. More specifically, >what I would like to do is the equivalent of: > >tell application "Nisus Writer" > activate > open document "document_path" >end tell > >in AppleEvent (I would prefer to not use Mac::Glue, because of memory >requirement...).
Awww. First, have you looked into MacPerl::DoAppleScript()? If not, it is worth looking at is. Slowest to execute, because of compilation time, but easiest to do (isn't that always the case? :). MacPerl::DoAppleScript('tell app "Nisus Writer" to activate'); Then, of course, there is Mac::OSA (and Mac::OSA::Simple), which functions like MacPerl::DoAppleScript, in that it can compile and execute an AppleScript, but you can take a single script and compile it once, and execute it many times. use Mac::OSA::Simple; $script = compile_applescript('tell app "Nisus Writer" to activate'); $script->execute; $script->save('HD:Desktop Folder:compile script'); And just for completeness, there's Mac::Glue. use Mac::Glue; $nisus = new Mac::Glue 'Nisus Writer'; $nisus->activate; But to Apple events: your first stop should be to macperlcat.pod, which comes with MacPerl, and describes how to do Apple events. It is not easy, but it is doable. I don't know the signature of Nisus Writer, so I am going to just assume it is NISU. You need to actually find out what it is. Then you can do: #!perl -w use Mac::AppleEvents; my(%ae, $event, $reply); use strict; %ae = ( target => 'NISY', class => 'misc', id => 'actv', params => [''], ); $event = AEBuildAppleEvent($ae{class}, $ae{id}, typeApplSignature, $ae{target}, kAutoGenerateReturnID, kAnyTransactionID, @{$ae{params}} ) or die $^E; $reply = AESend($event, kAEWaitReply) or die $^E; AEDisposeDesc $event; AEDisposeDesc $reply; $ae{class} = 'aevt'; $ae{id} = 'odoc'; $ae{params} = [ "'----':obj {want:type(file), from:null(), " . "form:name, seld:TEXT(\@)}", "HD:Desktop Folder:file" ]; $event = AEBuildAppleEvent($ae{class}, $ae{id}, typeApplSignature, $ae{target}, kAutoGenerateReturnID, kAnyTransactionID, @{$ae{params}} ) or die $^E; $reply = AESend($event, kAEWaitReply) or die $^E; AEDisposeDesc $event; AEDisposeDesc $reply; Yikes! OK, so there is also a *fifth* way to do it, using Mac::AppleEvents::Simple. use Mac::AppleEvents::Simple; do_event(qw/misc actv R*ch/); die $^E if $^E; do_event(qw/aevt odoc R*ch/, "'----':obj {want:type(file), from:null(), " . "form:name, seld:TEXT(\@)}", "HD:Desktop Folder:file" ); die $^E if $^E; As you can see, the essential portions of the event are the same as in the previous method, but the rest is taken care of for you: do_event builds, adds in the various parameters, sends, and disposes. Hope that helps, -- Chris Nandor [EMAIL PROTECTED] http://pudge.net/ Open Source Development Network [EMAIL PROTECTED] http://osdn.com/