Re: sub-routines' error
Re: sub-routines' error
- Subject: Re: sub-routines' error
- From: Axel Luttgens <email@hidden>
- Date: Wed, 10 May 2017 15:46:06 +0200
- Ironport-phdr: 9a23:bm24Mx92gNi5Rv9uRHKM819IXTAuvvDOBiVQ1KB90OocTK2v8tzYMVDF4r011RmSAtWdtqoMotGVmp6jcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS46tL2HV93Sp8HZGEw3nMQduLf70ApKXkt+6zfua/5zIfx4OjSKlZb40JxKz+1bru9ESkLdlf68q11Odq2NQf+lNznlpPU7Wgg3x/NyY+J947z8Wsuo588MGWqL/KfcWV7tdWR02PmR9wND3qRbOSxDHsnIMX2FQlgdUHwfI6grSRZTgtCbm8OBwjnrJdfbqRKw5DGzxp5xgTwXl3X8K
> Le 10 mai 2017 à 13:59, Maik Waschfeld a écrit :
>
> Hi AS-users,
>
> I’m trying to get a little deeper into the sub-routine-thing.
> But I’m stuck at a strange error -1708, that I can reproduce with the following script.
>
> […]
>
> When selecting more than one file, so that the sub-routine runs multiple times, I get this error:
> error „«script» doesn’t understand the message „the_Name“.“ number -1708 from «script»
>
> As far as I understand AppleScript, there’s basically nothing wrong with the script.
>
> If I replace the „my the_Name(the_File)“ line with
> tell application "Finder"
> set the_Name to name of the_File
> end tell
> no error comes up, even when I select quite a lot files.
>
> Any hints, how I get it to work, anyway?
Hello Maik,
This is a nice example of name-space clash in AppleScript. :-)
You may get the gist with that minimal piece:
SomeFunction()
--> "xyz"
SomeFunction()
--> error "«script» doesn’t understand the message « SomeFunction »." ...
on SomeFunction()
set SomeFunction to "xyz"
end SomeFunction
On first call of SomeFunction, since the name "SomeFunction" is followed by parentheses, the interpretor looks for a handler named that way, finds it and executes it.
Through that execution, implicit global variable "SomeFunction" is created (and value "xyz" is returned from the handler’s execution, since it’s the last value created through the handler’s execution).
On second call, AppleScript complains about not being able to find a handler named "SomeFunction", since the global variable now hides it.
You may try to avoid the problem by making the identifier local to the handler:
SomeFunction()
--> "xyz"
SomeFunction()
—> "xyz"
on SomeFunction()
local SomeFunction
set SomeFunction to "xyz"
end SomeFunction
But this tends to become quite ambiguous. ;-)
HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden