At 21:44 +0100 12/10/02, allan wrote:
hi

2 small problems.

i like to know how to close a program like Internet Explorer from perl.
the little script below seem to work for me, but i guess there must be
a cleaner and more correct way.

also i'm interesed in opening a browser with a valid internet address
as argument but i can't find out the syntax for mac os x - can anyone
give a hand with that?
One good way is to use AppleScript for both of these, with the "osascript" command.

The following simple AppleScript will kill Internet Explorer:

-----
tell application "Internet Explorer"
quit
end tell
-----

The following simple AppleScript will tell IE to load a URL with the "OpenURL" command, launching it if IE is not running:

-----
tell application "Internet Explorer"
openURL "http://www.example.com";
end tell
-----

You could write these scripts into a file and call them with osascript:

% osascript quitIE.txt

... or you could call osascript with one -e argument for each line of the AppleScript:

% osascript -e 'tell application "Internet Explorer"' -e 'OpenURL "http://www.example.com";' -e 'end tell'
% osascript -e 'tell application "Internet Explorer"' -e 'quit' -e 'end tell'

You can call osascript from within your Perl script and pass multiple -e arguments to it. I've done this and it works well.

With Carbon apps like IE, you generally can't pass arguments to them from the command line.

adam


thanks
./allan

# killing
my @output = `ps aux | grep '/Applications/Internet Explorer.app'`;

foreach my $line (@output) {
    if ($line =~
m,^\s*$ENV{LOGNAME}\s+(\d+).+\d+:\d+.\d+\s+/Applications/Internet
Explorer.app,) {
        system("kill", $1)
    }
}



Reply via email to