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: Nigel Garvey <email@hidden>
- Date: Sat, 9 Feb 2002 00:47:08 +0000
Eric Schult wrote on Fri, 08 Feb 2002 09:32:05 -0600:
>
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?
[...]
>
on run
>
tell application "Finder"
>
set thisFolder to choose folder with prompt "Pick a folder:"
>
fileList(thisFolder) of me
>
end tell
>
end run
[...]
>
on fileList(thisFolder)
>
tell application "Finder"
>
set fileList to name of every file in thisFolder
It looks very much as though by having a variable inside the handler with
the same name as the handler itself, the variable's being treated as the
global that holds the handler. In other words, when fileList is set to
'name of every file in thisFolder', the action is global and 'fileList'
ceases to refer to the handler elsewhere in the script. As globals
persist over subsequent runs of the script, fileList still contains the
'name of every file in thisFolder' the next time the script's run,
causing confusion when it's treated as a handler.
One cure is to declare fileList as a local variable inside the handler:
on fileList(thisFolder)
local fileList
tell application "Finder"
set fileList to name of every file in thisFolder
Better still, give different names to the handler and the variables it
uses.
NG
_______________________________________________
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.