The Applescript documentation says that as of Yosemite, parameters for handlers can be made optional.
From the section 'Parameter Specifications':
Labeled parameters may be declared with a default value by following the formal parameter name with :literal. Doing so makes the parameter optional when called. For example, this declares a make handler with a default value for the with data parameter:
on make new theClass with data theData : missing valueThis handler can now be called without supplying a with data parameter; the handler would see theData set to the specified default missing value, which it could then test for and handle appropriately.
So, being in need of a handler with optional parameters, I tried to create one. I have got this far:
set theResult to Create of me given the string:"stuff", info:"this"
on Create given info:missing value, thestring:"stuff"
if info is missing value then
set present to false
else
set present to true
end if
return {present, thestring}
end Create
which compiles, but gives me the error 'The variable thestring is not defined.'
If I call it with only one parameter:
set theResult to Create of me given thestring:"stuff"
I receive the error: 'The info parameter is missing for Create.' i.e. the parameter isn't optional after all.
How can I get optional parameters working in Applescript handlers?