• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Subroutine that works only on the 1st run
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: Maximum list size [was Re: Sifting a list sans loop]
  • Next by Date: Re: script object property contamination
  • Previous by thread: Re: Subroutine that works only on the 1st run
  • Next by thread: Re: Maximum list size [was Re: Sifting a list sans loop]
  • Index(es):
    • Date
    • Thread