[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Suggestion for a MacPerl Extension



PVHP@LNS62.LNS.CORNELL.EDU writes:
} 
} In a similar vein I have a problem with the following web page retriever & 
} optional viewer. It employs a silly little DoAppleScipt call that I would like 
} to avoid (script slows down noticably there BTW):
} 
}  #!/usr/bin/perl
} 
}  my %defaults = (
}  "Wilson Lab/CLEO/CESR Entry Page" =>  'http://w4.lns.cornell.edu/',
}  "Yahoo!"                          =>  'http://www.yahoo.com/',
}  "CUinfo-Home Page"                =>  'http://www.cornell.edu/',
}  );
} 
}  my $tmp_folder = 'myMac:tmp:';
}  my $browser = "myMac:Netscape Navigator Folder:Netscape Navigator 2.02";
} 
}  my $tmp_folder_slashed = join('/',split(/\:/,$tmp_folder));
}  my $localhost = 'localhost';
}  my @file_attributes = ("McPL", "TEXT");
} 
}  require "GUSI.ph";
}  require "url_get.pl";  # <- this one works on some servers but I will switch
}                         #    to maclibwww soon!
} 
}  #-----------------------------------------------------------------
} 
}  my $quit = 2;
}  my $decision;
} 
} # <other parts of this script snipped>
} 
}  $decision = MacPerl::Answer(
}     "Fire up a web browser now to look at\n$file\n?", "OK", "Skip", "Cancel");
}  if ($decision != 2) { 
}      &MacPerl::Quit($quit); 

You realize that MacPerl::Quit does not actually quit, but sets a flag
that determines what MacPerl does when it hits an exit?  You want an
exit() here.  I usually put my MacPerl::Quit at the very beginning of my
scripts.

}  }
}  else {
}      if (!@html) {
}          $file = &StandardFile::GetFile("Please select a local file:","$tmp_folder");
}      }
}      my $script = 
} 
}      "tell application \"$browser\"\n".
}      "        GetURL \"file://$localhost/$tmp_folder_slashed/$file\"\n".
}      "           activate\n".
}      "end tell\n";
} 
}      &MacPerl::DoAppleScript($script);
}      &MacPerl::Quit($quit);
}  }
} 
} __END__
} 
} OK so here are my questions: 
} 
} 1) Is there a way to call Internet Config to fire up the browser & look at 
}    the localhost file? Scripting like that would seem to 
}    be more Mac-platform independent (I could then copy script over to boss's 
}    Mac & have it use his favorite browser e.g.)
}    From what I have seen of Internet Config docs it appears to support only C 
}    function calls and I have not seen any obvious XS code that will allow a 
}    MacPerl call to Internet Config. Did I overlook something?

Not that I know of, but you realize that, with the way Applescript
works, it'll ask you where $browser is the first time you run it on a new
machine anyway?  Getting it not to ask is a pain, because, as far as I
can tell, you need to use the Script Editor once with the same syntax to
get the application selected automatically.  You'll wind up hand editing
the script anyway.

} 
} This particular application needs to run at a non-busy time each day to 
} retrieve a web page URL. This requirement leads to my next question:
} 
} 2) How do I write cron jobs in MacPerl? Assuming I call perl builtins like 
}    localtime() & sleep() - Are there any special tricks involved in having a 
}    Perl app "running in the background"? I would assume that leaving a droplet 
}    (or alias) in the system folder would be necessary - does anyone have any 
}    other recommendations? I would like to lower the RAM footprint as much as 
}    possible.
} 

Although you can probably do it in MacPerl, the easiest way is to use
one of the Macintosh crons.  You can find them in the Info-Mac archives.
I like Mark Malson's because of the simplicity of the way it works, but
the others have their own features.  I cron launch MacPerl scripts
several times a day.

} FWIW: I am testing this on a PowerMac w/ System 7.5.3 & MacPerl 5.0.7.r1m.
} 
} Thank you.
} 
} Peter Prymmer  "clueless newbie MacOS hacker"
} pvhp@lns62.lns.cornell.edu
} 
} 

(Incidentally, I got my Ph. D. in Physics at Cornell.  Spent a lot of
time in Clark, Newman, and Rocky Barracks, which some know as
Rockefeller Hall)

---
--------
Paul J. Schinder
NASA Goddard Space Flight Center,
Code 693, Greenbelt, MD 20771 USA
schinder@pjstoaster.pg.md.us