Re: Two things I noticed in a simple Finder script
Re: Two things I noticed in a simple Finder script
- Subject: Re: Two things I noticed in a simple Finder script
- From: Jan Pieter Kunst <email@hidden>
- Date: Sun, 03 Jun 2001 00:15:48 +0200
Paul Berkowitz (email@hidden) schreef op 02-06-2001 23:07 :
>
On 6/2/01 8:47 AM, "Jan Pieter Kunst" <email@hidden> wrote:
>
>
>
>
> Another thing I noticed is that if there are no windows open, I can't use
>
> Applescript to check if a certain window is open without getting into some
>
> infinite loop. In other words, this:
>
>
>
>
>
> set x to container window of folder ...
>
> set y to container windows -- gives {} if there are no open windows
>
> if y contains x then ... -- script gets stuck in an infinite loop if y = {}
>
>
Use a try block:
>
>
set x to container window of folder ...
>
set y to container windows -- gives {} if there are no open windows
>
try
>
if y contains x then ...
>
on error -- if you want to
>
beep
>
display dialog "Sorry. There are no open windows."
>
end try
Thanks for the suggestion, Paul. It sort of works, but it's hardly the most
efficient solution. What happens is that the infinite loop starts and runs
for a long time, and instead of stopping with a stack overflow, the script
now continues. However, waiting for the script to take that useless trip up
that very long stairway and stopping it just before it bumps its head on the
ceiling takes a lot more time than checking for the empty list of container
windows beforehand.
JP