Re: a handler runs after compile, but never again
Re: a handler runs after compile, but never again
- Subject: Re: a handler runs after compile, but never again
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 30 Nov 2003 10:40:40 -0800
On 11/30/03 8:08 AM, "Michelle Steiner" <email@hidden> wrote:
>
On Nov 30, 2003, at 8:40 AM, Matyas Ferenc Farkas wrote:
>
>
> there is the troublemaker:
>
>
The problem is that you named a variable within the handler the same as
>
the handler. I don't know why this is a problem, but by changing the
>
name of the variable, I was able to fix it.
Because the name of a handler has exactly the same status as a global
variable - it has global scope as a variable name, and the name of the
variable within the handler wasn't explicitly declared as local. So
'theContainer' - a global variable - got redefined as a string during the
first run of the handler, and when "called" the second time, the script
didn't know what to do. Globals are persistent between script runs, just
like properties (in fact, a property is nothing but a glabl that's
initialized when compiled), so the new definition for 'theContainer' - a
string - is in effert when you run the script the second time. You could
have instead declared 'theContainer' as local within the handler
on theContainer(filepath)
local theContainer
but it's much less confusing (to humans) to give the variable in the
handler a different name, as Michelle did. (And that makes it local by
default, since it's not already defined as a global.)
>
>
I also simplified the script a bit while I was at it.
Or, neater again:
set filepathstring to "Macintosh
HD:Users:spoun:Desktop:demofolder:mappa Ordner:mappa2:mappa3:"
log my theContainer(filepathstring)
on theContainer(filepath)
set AppleScript's text item delimiters to {":"}
set aContainer to (filepath's text items 1 thru -3) as string & ":"
set AppleScript's text item delimiters to {""}
return aContainer
end theContainer
And this works too, but I wouldn't recommend it:
set filepathstring to "Macintosh
HD:Users:spoun:Desktop:demofolder:mappa Ordner:mappa2:mappa3:"
log my theContainer(filepathstring)
on theContainer(filepath)
local theContainer
set AppleScript's text item delimiters to {":"}
set theContainer to (filepath's text items 1 thru -3) as string & ":"
set AppleScript's text item delimiters to {""}
return theContainer
end theContainer
--
Paul Berkowitz
_______________________________________________
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.