At 13:05 +0100 2001.04.11, Alan Fry wrote:
>However that would not seem to me to offer much advantage over the
>default Mac arrangement. It is after all very easy to change the
>default browser type in InternetConfig by the 'Internet' Control
>Panel. It strikes me it might be unlikely the user would choose a
>different browser for your program than the one he or she regularly
>uses? But maybe I've missed a point here.

That's my thought, too.

Anyway, a few notes:

* If you have the Mac::InternetConfig from the cpan-mac distribution, you
can do this, instead of the three lines of code you (Morbus) have:

        use Mac::InternetConfig;
        GetURL($url);

* You _can_, though this may not be the best thing to do, temporarily
change the user's IC prefs.  I don't know how easy this is to do; I don't
think Mac::InternetConfig can do it.  You might be able to with some Apple
events.  Probably not the best thing, though, since if you resort to Apple
events, you might as well:

* Talk to the application with Apple events/AppleScript.

Alan's script will launch the application, but you still need to talk to
it.  Some options (all assumed $app (four-char signature) or $path (full
path to application), and $url, are defined):

* AppleScript, with path

        $path =~ s/"/\"/g;
        $url  =~ s/"/\"/g;
        MacPerl::DoAppleScript(qq[tell application "$path" to GetURL "$url"]);

* AppleScript, with signature

Um.  I forget how to do this.  :-)

* Apple events, with path

Note: here we need to launch with Mac::Processes and capture the process
serial number.  This requires a fix to Mac::Processes that is in the
cpan-mac distribution, so LaunchApplication will return the PSN.
Otherwise, you would need to launch the app, then go through all the
processes to find the PSN for the app you want.

        use Mac::AppleEvents::Simple ':all';
        use Mac::Processes;
        # switch app to front
        $Mac::AppleEvents::Simple::SWITCH = 1;

        my $lp = LaunchParam->new(
                launchControlFlags => (launchContinue | launchNoFileFlags
                                | launchDontSwitch),
                launchAppSpec => $path
        );
        my $psn = LaunchApplication($lp) or die "Cannot launch '$path': $^E";

        do_event('GURL', 'GURL',
                { typeProcessSerialNumber() => pack_psn($psn) },
                "'----':TEXT(\@)", $url
        );

* Apple events, with signature

        use Mac::AppleEvents::Simple;
        $Mac::AppleEvents::Simple::SWITCH = 1;
        do_event('GURL', 'GURL', $app, "'----':TEXT(\@)", $url);

* Mac::Glue, with path

Now, the problem with Mac::Glue is that you (basically) need to create a
glue file for each individual application you want to control.  Since you
will be letting the user choose the application, you don't know if the
application has a glue or not.  You _can_ get around this by cheating.
Create a glue for a browser, and then use that glue name.  But pass to it
whatever path you have chosen.  If the path is for Netscape Communicator,
then by golly, it will send all events for the glue to Netscape
Communicator, even though the glue is designed for Internet Explorer.

        use Mac::Glue;
        my $http = new Mac::Glue 'Internet Explorer', path => $path;
        $http->geturl($url);

This will, behind the scenes, do the thing with LaunchApplication, get the
PSN, convert it to a long with pack_psn(), and set it as the address.

Of course, most of the events supported by the Internet Explorer glue won't
work with Netscape Communicator.  But we don't care in this case, because
we only care about the GetURL event, which _is_ supported the same in all
Mac browsers (at least, it should be, in all reasonable Mac browsers).

One last example:

* Mac::Glue, with signature

Mac::Glue is not designed to accept signatures in the constructor.  You can
fake it with even more cheating.  The address for the app is stored in the
ADDRESS key of the object, with the value as a hashref, where the only key
is the address type (typeApplSignature for apps, typeProcessSerialNumber
for path/PSN), and the value is the address.

        use Mac::Glue;
        my $http = new Mac::Glue 'Internet Explorer';
        $http->{ADDRESS} = { sign => $app };
        $http->geturl($url);

*Phew*!  That should give you enough options, I hope.

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

Reply via email to