Re: Subroutine that works only on the 1st run
Re: Subroutine that works only on the 1st run
- Subject: Re: Subroutine that works only on the 1st run
- From: has <email@hidden>
- Date: Sat, 9 Feb 2002 13:14:17 +0000
Eric Schult wrote:
>
This script works the first time it's run, but fails on any subsequent run,
>
saying, "The <script> doesn't understand the fileList message. The same
>
thing happens in both the "on run" and "on open" routines. Can anybody guide
>
me?
You just gotta take more care where you put things. ;)
Here's where you're going wrong:
>
on ***fileList***(thisFolder)
>
tell application "Finder"
>
set ***fileList*** to name of every file in thisFolder
First you declare 'fileList' and assign a handler to it. Later on you
assign a new value to 'fileList', replacing the handler object that was
previously there. Look at it this way: with properties, you simultaneously
declare a global variable and assign a value to it:
property blah : ...
The contents of variable 'blah' are accessible and modifiable from anywhere
in your script. It's the same thing with handlers:
on blah...
end blah
Again, just a container named 'blah' holding an object (in this case a
handler). (The funny thing about AS's basic design is it's surprisingly
logical, simple and consistent... but nobody ever really tells you this.
Hence these little... 'surprises'.;)
What you're doing is replacing the original contents of fileList (a handler
object) with a list object: it's as if your script is rewriting itself as
you run it!
The solution's easy enough: either use different identifiers (I'd suggest
calling the handler 'getFileList'), or limit your inner variable's scope by
adding a 'local fileList' declaration to the start of the fileList handler.
(See pages 311-323 of the ASLG for more info.)
HTH
has
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.